WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Archive Subcat Exclusion - The RIGHT way? (5 posts)

  1. Ivovic
    Member
    Posted 6 years ago #

    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:

    Maincat
    +- 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.

    Thanks.

  2. Ivovic
    Member
    Posted 6 years ago #

    A gentle bump for a different time-zone ;)

  3. Ivovic
    Member
    Posted 6 years ago #

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

    Cheers guys :)

  4. Ivovic
    Member
    Posted 6 years ago #

    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.

  5. houseofstrauss
    Member
    Posted 6 years ago #

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

    '<?php
    /*
    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(); ?>

    </div>
    <?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?

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic