WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple loops and Pagination issues (5 posts)

  1. curtisbillue
    Member
    Posted 1 year ago #

    I've read several forums on this, tutorials and discussions on multiple loops and page numbers either not showing or recycling back to the starting posts, however I can't seem to find the right combination to make it work. Hoping someone can give me some sort of insight.

    Here's the site and two places in particular: http://s-usih.org and http://s-usih.org/blog
    Here's the pastebin of the loops:

    http://pastebin.com/iEKm44Mq

    I have two custom WP_Query loops on a static home page that filter by category and showposts and wp_reset_postdata at the end of each. Those work fine. When I click on a title and go to each page and go previous and next, it works and will cycle through all of the posts.

    The third main loop is on my blogtemplate php file, and it is a query_posts filtering by category and posts_per_page, which works. However when I put any type of nav feature it either doesn't show, or does show and the pages just restart back to the same posts no matter what page you try. Even this latest version I put a plugin WP Simple Pagination and although it shows the pages, it is stuck in that same loop again of showing the same posts regardless of what page number you click.

    What am I missing (besides great wisdom and experience)? I feel like I am close, just frustrated at my lack of understanding. Thanks CB

  2. Chris
    Member
    Posted 1 year ago #

    Have you tried adding the 'paged' parameter? So instead of just

    //and 1 main loop on the blogtemplate where main blog is located:
    
    <?php query_posts('cat=1941&posts_per_page=3');

    maybe like this:

    // Normally the page number URL parameter should be 'paged' but I've also seen 'page' lately, so..
    $currentPage = get_query_var( 'page' ) ? (int) get_query_var( 'page' ) : null;
    
    if( $currentPage == null ) {
      $currentPage = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
    }
    
    $currentPage = abs( $currentPage );
    
    query_posts( 'cat=1941&posts_per_page=3&paged=' . $currentPage );
  3. curtisbillue
    Member
    Posted 1 year ago #

    Haven't tried that. Let me check it out and see what happens. Thanks Chris.

  4. curtisbillue
    Member
    Posted 1 year ago #

    Awesome, that worked! Adding in the paged parameter and putting the plugin Simple Pagination worked. Thanks Chris!

  5. Shazzad Hossain Khan
    Member
    Posted 6 months ago #

    If you want to do it without a plugin, you can try this snippet - Multiple Post Type Loop & Pagination by Shortcode

Topic Closed

This topic has been closed to new replies.

About this Topic