Forums

[resolved] Custom Number of Posts in a Category (3 posts)

  1. nast0
    Member
    Posted 7 months ago #

    I've created a custom category page (archive-211.php) which will be a category for videos. If someone visits this category (www.url.com/?cat=211) I don't want them to see 6 posts on one page like they do in my other categories... i want them to only see 1 post, and the usual (next >) links. I can't edit the settings, as that would change ALL my categories.

    I can't find anywhere how to do this. I've read the codex, Googled, etc but no luck.

    Any pointers on how I get the loop to stop after 1 post in my category template?

    Thanks,
    n

  2. MichaelH
    moderator
    Posted 7 months ago #

    Interesting that the archive-211.php works--thought that would need to be category-211.php according to the Template Hierarchy article.

    Here's an example of code you can use in your category template to show 3 posts per page, regardless of what's in your Settings->Reading.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string . '&paged='.$paged .'&showposts=3');
    ?>

  3. nast0
    Member
    Posted 7 months ago #

    That was a typo actually, as I have an archive.php I got confuddled, you're correct that my file is called "category-211.php".

    I've dropped the code right in, and it works like a charm, many thanks for the help.

    n

Reply

You must log in to post.

About this Topic