WordPress.org

Forums

[resolved] Same posts repeat on next/prev page links (multiple loops) (10 posts)

  1. nouman6
    Member
    Posted 5 years ago #

    Hey Guys.

    so the issue can be seen at:
    http://lalawag.com/beta/

    by clicking prev/next, the same posts are displayed in the recent articles section.

    The code for my page is as follows: (three loops, first displays most recent post and discludes category 'featured'. Second loop displays three posts from category 'featured', and finally the last post discludes the category featured AND skips the first post. This is the loop that holds the next/prev links)

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. nouman6
    Member
    Posted 5 years ago #

    Sorry, the pastebin url is: http://wordpress.pastebin.ca/1866895

  3. alchymyth
    Forum Moderator
    Posted 5 years ago #

    you have probably already read this:
    http://codex.wordpress.org/Function_Reference/query_posts#Pagination_Parameters
    it is not very clearly documented how to do pagination with custom queries.
    this article might be a bit clearer:
    http://stylizedweb.com/2008/08/13/query_posts-pagination-problem/

    and imho, pagination does not work with 'offset' in the same query;

    you may need to find a different method to exclude tht first post - such as saving the id of the first post in a variable and using

    'post__not_in' => array(6,2,8) - exclusion, lets you specify the post IDs NOT to retrieve

    http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters

  4. nouman6
    Member
    Posted 5 years ago #

    thanks for the reply alchymyth. Tried out the methods described on that blog as well as the post_not_in (which worked by excluding the post) but both still had repeating posts in pagination.

    Pretty stumped on multiple loops right now, but maybe a better look at what I'm trying to do in general.

    Latest Post
    - Get's the latest (1) Post and displays it a certain way.

    Featured Posts
    - Get's posts in the Category featured, and limits the display to 3 posts styled in a certain way..

    Posts
    - Excludes the first post, and the category of featured posts.
    - Is the only loop with prev/next pagination links.

    So far all the ways I've tried just has the same set of posts display page after page.

    and thanks again for the quality reply!

  5. alchymyth
    Forum Moderator
    Posted 5 years ago #

    can you 'pastebin' the latest version of your php file ?

  6. nouman6
    Member
    Posted 5 years ago #

    Yep, http://pastebin.com/93CCQ4kB

    sorta re-did some of the changes I made, but that's where it's at and not working

    thanks again!

  7. Safirul Alredha
    Member
    Posted 5 years ago #

    First off, add wp_reset_query() after each query.

    2nd, query_posts + pagination + offset doesn't work well if you don't know your way around. See: http://weblogtoolscollection.com/archives/2008/06/19/how-to-offsets-and-paging/

  8. nouman6
    Member
    Posted 5 years ago #

    Hey Zeo, no luck still.

    I removed offset completely, just using post_not_in, and adding wp_reset_query like you suggested, and still the posts repeat:

    http://pastebin.org/171665
    http://lalawag.com/beta/

  9. Safirul Alredha
    Member
    Posted 5 years ago #

    see whether this work:

    query_posts(array('post__not_in' => $ids, 'paged' => $paged));

    and please use posts_per_page instead of showposts

  10. nouman6
    Member
    Posted 5 years ago #

    Hey Zeo,

    thanks for the help! That seemed to fix the problem

Topic Closed

This topic has been closed to new replies.

About this Topic