• Resolved ivovic

    (@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:

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ivovic

    (@ivovic)

    A gentle bump for a different time-zone ??

    Thread Starter ivovic

    (@ivovic)

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

    Cheers guys ??

    Thread Starter ivovic

    (@ivovic)

    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

    ‘<?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

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