• I can’t figure out whats wrong with this code. I want it to show 10 blog posts on a page-which it does, but when you click on the “older post” link at the bottom it just re-hashes the same 10 blog posts instead of showing more of the older ones. Thank you all, your help is appreciated : )

    [code moderated - please follow the forum rules]

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must include the ‘paged’ argument to query_posts() to get pagination. Try changing this:

    <?php query_posts("posts_per_page=10"); ?>

    to this:

    <?php
    $paged = (intval(get_query_var('paged'))) ? get_query_var('paged') : 1;
    query_posts("posts_per_page=10&paged=$paged"); ?>
    Thread Starter dzupec

    (@dzupec)

    Hey vtxyzzy,

    Thank you so much this worked : ) Could you explain to me or show me where I can find the explanation for this? I just never had to add this before to get it to work.

    Thank you!

    When you click on a ‘Older posts’ link, it creates a URL like this if you are using pretty permalinks: https://yoursite.com/page/2

    The ‘/page/2’ part is the way that the page number is passed to the next query. In order for that query to actually use the page number, the ‘paged’ argument needs to be included. You get the value of the page from the URL using get_query_var().

    Thread Starter dzupec

    (@dzupec)

    Thank you for explaining that too me : )

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loop for posts isn't working correctly’ is closed to new replies.