show at most n posts EXCLUDING certain categories? (5 posts)

  1. ia
    Posted 8 years ago #

    When I say "Show at most: 5 posts" in the Reading option in the dashboard, it only displays 3 posts in the frontpage. I suspect that it's because of this code (my index.php loop):

    <?php while (have_posts()) : the_post(); ?>
    <?php if ( in_category('5') || in_category('6') ) { ?>
    ...do nothing, haha...
    <?php } else { ?>
    ...poststuff in the loop...
    <?php } ?>

    Right now, in my testblog, I have 2 categories that fall under categories 5 and/or 6, so that seems to be the "missing" 2 (2+3=5, yay). Is there any way I can hide certain categories from the frontpage so that WordPress can also skip their count?

    I think this is a minor issue for me since I simply want to see how things look with different number of posts (as few as possible, perhaps), but if I do choose 1 post, it won't show anything due to the same reason. It's kind of weird, don't you think?

  2. Jonathan Landrum
    Posted 8 years ago #

    Yeah, that is strange. I think it has something to do with the way WP counts the posts. This plugin might be easier to use:
    Then again, I've never used it and don't know if it won't do the same thing. :o\

  3. tsguitar
    Posted 8 years ago #

    I'm using query_posts to exclude one category from my home page. query_posts would solve part of your problem in that it doesn't count the posts from the excluded categories in the amount of posts to the home page. It will still pull up 5 entries on the home page. The beginning of my loop looks like this:
    <?php if (have_posts()) : query_posts($query_string .'&cat=-2'); while (have_posts()) : the_post();

    query_posts doesn't work well to exclude multiple categories, though. Still, have a look at the Codex page about it because it mentions a method to exclude multiple posts on that page. Give it a shot and see if it works.

  4. ia
    Posted 8 years ago #

    Thanks for all your input; I'll let you know. (I'm busy with other things so getting that done might be a while :)

  5. ia
    Posted 8 years ago #


    the Solvent plugin was discontinued, I'm trying the plugin from that link. :D

Topic Closed

This topic has been closed to new replies.

About this Topic