WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. MultiformeIngegno
    Member
    Posted 1 year ago #

    What's wrong with this code?
    http://pastebin.com/Cv7yDsNv

    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. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    This is your problem.

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

    More info:
    http://codex.wordpress.org/Function_Reference/query_posts#Pagination

  3. MultiformeIngegno
    Member
    Posted 1 year ago #

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

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 1 year ago #

    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
    Member
    Posted 1 year 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