[resolved] Loop: pagination doesn't work (5 posts)

  1. MultiformeIngegno
    Posted 3 years ago #

    What's wrong with this code?

    Why if I click on "Next page" I go to /page/2/ but the same posts of page 1 are displayed? If I click on "next page" on /page/2/ I go to /page/3/ but still the same posts are shown (and so on)..

  2. This is your problem.

    query_posts( 'cat=1&posts_per_page=2' );

    More info:

  3. MultiformeIngegno
    Posted 3 years ago #

    Thanks, marked as solved.
    Out of curiosity, why on category.php pagination works without having the paged param?

  4. Because you're not doing a query_posts there?

    The query_posts() function changes the main query for the page. When you use it, you override the "automatic" main query which takes everything into account normally, and tell it that you want to do something other than the default.

    Really, you should use the pre_get_posts filter instead of the query_posts() function. Then you can modify the main query instead of overriding it entirely.

  5. MultiformeIngegno
    Posted 3 years ago #

    Thanks, I'll read about pre_get_posts. Never heard of it before, always used query_posts. Will have a look! ;)

Topic Closed

This topic has been closed to new replies.

About this Topic