Skip sub-categories in The Loop? (3 posts)

  1. jonasb
    Posted 9 years ago #

    This is probably an extremely easy one but I can't get it to work even after browsing the support forums/help pages.

    I have several categories and sub-categories. When I click a category it will output all posts from that category and sub-categories in THE LOOP.

    <?php while (have_posts()) : the_post(); ?>
    <--- do stuff --->
    <?php endwhile; ?>

    But when I click the parent category I just want it to show the posts in that category ONLY and not posts in its' sub-categories/children categories.

    Aren't I supposed to just add, for example, this above:
    <?php query_posts('cat=4'); ?>
    if I just want to list posts from category 4 in the loop?

    But it still lists posts in category 4 and all it's sub-categories (which have ID 16,17,18 and 19).

    Am I missing something? Running WordPress 2.0.4.

  2. tsguitar
    Posted 9 years ago #

    My immediate response to this is to just not use subcategories. Wouldn't that solve this problem? I mean, if a user clicks on the category and can't see any subcategory posts, what's the point of having a subcategory?

    <?php query_posts('cat=4'); ?> would return all posts within category 4. Subcategories of category 4 are in category 4 and are therefore returned. You want to exclude categories, right? Give this a try:

  3. jonasb
    Posted 9 years ago #

    I started to think when you wrote that and what I have is more or less a site with a bunch of reviews:
    - Application 1
    - Application 2
    Desktop Publishing
    - Application 1
    - Application 2
    ...and so on!

    But I realized - Pages are more made for this kind of information since it can handle a hiearchy aswell. So I better go with that I guess. The only PROBLEM I see with this is if I have an application that should exist under two parents. For example if there's some review of an application that is both a Graphics and a Desktop Publising software. Any suggestions?

Topic Closed

This topic has been closed to new replies.

About this Topic