how to exclude category from home page but ensure minimum 5 posts per page (6 posts)

  1. burpen
    Posted 6 years ago #

    Changing the query string to exclude a certain category from the home page works for me, but it seems as though this makes the "posts per page" parameter more of a "maximum posts per page" parameter.

    For example, if I'm excluding category X from my home page, I query for 5 posts per page, and 4 of my 5 most recent posts are in category X, then only one post (the only post that isn't in category X) displays on the home page. Likewise, the "older posts" pages display a maximum of 5 posts per page rather than simply 5 posts per page.

    Is there any way to query for posts in such a way that my category X articles do not add to the posts per page count? I would like to see exactly 5 posts per page on my home page, obviously excepting pages where I have less than 5 posts not in category X.

  2. burpen
    Posted 6 years ago #

    Oops, semi-misstated title for this topic. Should have been "exactly 5 posts per page"...

  3. henkholland
    Posted 6 years ago #

    1. What is your number of posts setting under Dasboard/Settings/Reading?

    I am using this for somethng similar:

    <?php query_posts('category_id=#&showposts=#');?>
    <?php $posts = get_posts('category=3,9&numberposts=5&offset=0');
    	foreach ($posts as $post) : start_wp(); ?>
    <li><h5><a href="<?php echo get_permalink() ?>"><?php the_title(); ?></a></h5></li>
    <li><div class = "shortlist">
    <?php the_excerpt_rereloaded('11','---&raquo;&raquo;','no','plain','no'); ?>
    <?php endforeach; ?>

    This includes categories 3 and 9 and shows 5 posts ; the_excerpts could be the_content offcourse.
    When you set numberposts to 0 it uses the number set under Reading.

  4. burpen
    Posted 6 years ago #

    I think I fixed it. I wanted to exclude multiple categories but I was passing the parameter to query_posts like so:
    $posts = query_posts($query_string . "&cat=-35-21-73");

    This was being discarded as an invalid parameter. I was getting all posts and filtering out the categories later on, so I never caught that my query_posts was failing. I really needed it to look like:
    $posts = query_posts($query_string . "&cat=-35,-21,-73");

  5. lividinstruments
    Posted 6 years ago #

    Where do you put this query?

  6. burpen
    Posted 6 years ago #

    @lividinstruments: Put it in your Loop. Look under the "Exclude Posts From Some Category" section in that link for an example.

Topic Closed

This topic has been closed to new replies.

About this Topic