[resolved] Exclude Category except for Single, Archive and Category (3 posts)

  1. valuxes
    Posted 6 years ago #

    I'm trying to exclude all posts on the Home Page alone for category '5', but want the posts displayed in single-post, category and archive view. I also want 8 posts on the Home Page.

    If I use the following code inside the Loop, the excluded posts are counted and I get less than 8 posts displayed:

    <?php if ( in_category('5') && !is_single() && !is_category() && !is_archive() ) continue; ?>

    So, I am thinking of using the following code just before the Loop:

    <?php query_posts($query_string . '&cat=-5&showposts=8'); ?>

    How do I specify not to exclude the posts for category 5 in the other views?


  2. esmi
    Forum Moderator
    Posted 6 years ago #

    Try using:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&cat=-5&posts_per_page=8&paged=' . $paged); ?>

    And create archive.php and category.php template files in your theme that do not include this custom query.

  3. valuxes
    Posted 6 years ago #

    I see. OK thanks, will try.

Topic Closed

This topic has been closed to new replies.

About this Topic