WordPress.org

Ready to get started?Download WordPress

Forums

Posts per page shows same posts on each page (7 posts)

  1. GPirie
    Member
    Posted 4 years ago #

    I've created custom page templates showing the posts for different categories on each page, and would like to limit the number of posts per page to 6.

    I've added query_posts('categoryname=news&posts_per_page=6'); to the page and it displays the correct category and limits it to 6 posts, however when I go to page/2 it displays the same 6 posts and so on.

    How do I get it to show the next 6 posts as I wish?

    Any help appreciated.

  2. MichaelH
    Member
    Posted 4 years ago #

    Example of proper pagination and corrected category_name:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=news&posts_per_page=6&paged=' . $paged);
    ?>
  3. nickbudden
    Member
    Posted 4 years ago #

    Is this code supposed to go into the header? I've tried it in a category template I've made, as I'm having the same problem, but the problem has continued.

  4. MichaelH
    Member
    Posted 4 years ago #

    Typically that goes in a category template.

  5. nickbudden
    Member
    Posted 4 years ago #

    Thank you, I think I'd put it in the wrong place because now it is working. Thanks again.

  6. nickbudden
    Member
    Posted 4 years ago #

    Sorry, but is it possible to have a different number of posts for the first page in the category, and a different number for all other pages in that category?

  7. MichaelH
    Member
    Posted 4 years ago #

    I thought I remember seeing someone with a solution for that question but I can't find it...it was in the forums I'm pretty sure.

Topic Closed

This topic has been closed to new replies.

About this Topic