[resolved] Pagination with custom loop not working (4 posts)

  1. macgamer
    Posted 3 years ago #

    On my site, I have a front page template with a custom loop query:

    <?php $args = array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 10, 'cat' => '-7, -8, -112','paged' =>get_query_var('paged') ); ?>
    				<?php $loop = new WP_Query( $args ); ?>
    				<?php if ( $loop->have_posts() ) : ?>
    					<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    Then after the loop,

    <?php get_template_part( 'loop-nav' ); ?>

    (Which is used throughout the rest of the site.)
    However, the pagination never shows, and setting the url to /page/2 doesn't change which posts get displayed. I've also tried just replacing the loop-nav template with stock WP pagination code, but that doesn't work either.

    Can anyone shed some light on this?

  2. Michael
    Part-Time Forum Moderator
    Posted 3 years ago #

    'loop-nav' is possibly/probably based on the default $wp_query object, while you are using $loop (?)

    what is the code of loop-nav.php?

    possibly try this hack:

    <?php $temp = $wp_query; $wp_query = null; $wp_query = $loop;
    get_template_part( 'loop-nav' );
    $wp_query = null; $wp_query = $temp; ?>

    slightly related:

  3. keesiemeijer
    Posted 3 years ago #

    Also, if this is a in a static front page (Page template) you need to use the "page" query variable.

    <?php $args = array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 10, 'cat' => '-7, -8, -112','paged' =>get_query_var('page') ); ?>


  4. macgamer
    Posted 3 years ago #

    @keesiemeijer: Thanks, your link solved it!

Topic Closed

This topic has been closed to new replies.

About this Topic