Support » Fixing WordPress » Specific category – override posts_per_page?

  • What code do I use to have a specific category override the set number of posts per page?

    (I’m positive this has been covered, but the search function’s limitations make it hard to find.)

    Also, why do excluded category posts count against the index page’s total post count? (For example, my posts per page is set to 10. If I exclude cat 6 from the index, and that cat has seven posts, I see only three posts on the index page no matter how many other posts exist in the other cats.)

Viewing 9 replies - 1 through 9 (of 9 total)
  • 1. You could probably use the following plugin. You could specify post-per-page for category view. Needs a bit of modification if you want to apply it to only certain categories.

    2. How do you exclude categories? Use the following plugin instead

    1. It’s kind of a catch-22: if I knew how to set up the plugin that way, I could probably set up the category template that way. 😉

    2. I use the same method that’s in the Codex:
    And that plugin is for including cats, not excluding them – a big difference seeing as I have 35 categories and will be changing them going forward.

    If at all possible, I’d like to code this directly into templates, so I’m not messing with templates AND plugins going forward. We’re talking about one category here, so going with plugins seems like overkill.

    1. What’s catch-22? Did I answer your question?? Further question?

    2. Ditch that method. Use the one of the advanced use of loop below it

    Something like the following
    // Get the last 10 posts in the special_cat category.
    <?php query_posts('category_name=special_cat&showposts=10'); ?>

    <?php while (have_posts()) : the_post(); ?>
    // Do special_cat stuff.
    <?php endwhile;?>

    By the way, you could exclude a category with the plugin I mentioned. Just use a negative value (e.g. '-6').

    1. Sorry, “catch-22” means that you can’t do one thing without doing another thing, but if you could do the other thing, you could do the first thing. I can’t use the plugin unless I know the code so I can change the plugin, so no, it didn’t answer my question.

    2. But I think this is really the answer to #1 (limiting posts for a specific category). It seems to work: I have a special template for this category, so I just stuck in this line before the loop:

    <?php query_posts('category_name=news&showposts=3'); ?>

    Thanks for that.

    Question #2 is still unsolved: excluding posts from the index page, and not counting them towards the posts_per_page limit.

    1. solved. (right?)

    2. Did you read this?
    By the way, you could exclude a category with the plugin I mentioned. Just use a negative value (e.g. '-6').

    1. Solved.

    2. Tried a negative number in the plugin, got an error. (Positive numbers work just fine.) Of course, we don’t know if the plugin will even solve this problem.

    2. Well it doesn’t give me an error, but it didn’t work for me either. So, make the following modification in the plugin

    Find the following
    $cat = explode('-',$q['cat']);

    Replace with the following
    $cat = explode('-',$cat);

    That seems to solve the post count problem. I’d still rather code directly, but it’ll do for a band-aid fix.


    Now If I can find the right URL to call a category-specific yearly archive page, I’ll be ready to concentrate on actual content. 😉

    I’ve edited this plugin to include multiple negatives

    Get the updated version here

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Specific category – override posts_per_page?’ is closed to new replies.