Support » Fixing WordPress » Archive Subcat Exclusion – The RIGHT way?

  • Resolved Ivovic


    Hi guys, I’m working with archive.php to display posts within a certain category but NOT the posts within any of the sub-categories (or category children as it were).

    So basically, it looks like this:

    +- Subcat1
    +- Subcat2

    When viewing Maincat, I want only the posts in that category to be displayed, not the posts in Subcats.

    The standard query_posts ‘&cat=-id1,-id2’ doesn’t actually exclude the subcats, as they seem to be fed simply because I’m viewing the parent category.

    Any idea how I can get around this and still get a properly paged category archive listing?

    I don’t want to have to manually check each result in The Loop to see if it’s in the subcats, because that will affect the number of results displayed, and screw up pagination.

    Any help would be greatly appreciated.


Viewing 4 replies - 1 through 4 (of 4 total)
  • A gentle bump for a different time-zone 😉

    Can any moderators think of a more appropriate forum for this post? If so, could you please move it?

    Cheers guys 🙂

    By chance, I figured out how to do this…

    If you want to exclude posts in children categories, while listing posts in the partent category only, use the get_posts function, instead of query_posts to fetch the listing.

    Trying to do this in 2.5 Here is my archive.php file

    Template Name: Archives

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    <div class=”middle”>

    <h2>Archives by Month:</h2>

      <?php wp_get_archives(‘type=monthly’); ?>

    <h2>Archives by Subject:</h2>

      <?php wp_list_categories(); ?>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>’

    Now where is query_posts ? I don’t see it.

    Can someone tell me how to exclude sub-cats in 2.5?


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Archive Subcat Exclusion – The RIGHT way?’ is closed to new replies.