Support » Fixing WordPress » Exclude Category except for Single, Archive and Category

  • Resolved valuxes

    (@valuxes)


    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?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    (@esmi)

    Forum Moderator

    Try using:

    <?php
    $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.

    I see. OK thanks, will try.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Category except for Single, Archive and Category’ is closed to new replies.