WordPress.org

Forums

[resolved] Pagination on homepage query not working (3 posts)

  1. greencode
    Member
    Posted 2 years ago #

    I have this same query and pagination working on the website's inner pages but when I come to add it to the homepage the pagination doesn't work. It just shows me the same posts on subsequent pages as it does on the 1st (home) page.

    Any ideas? Here's my codeā€¦

    <ul id="main" class="clearfix">
    
    <?php /* Start the Loop */
        $my_query = new WP_Query(array(
        	'cat' => '1',
        	'posts_per_page' => 2,
        	'post__not_in' => get_option('sticky_posts'),
        	'paged' => get_query_var('paged')));
        while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
    
    <li class="grid_3">
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    </li>
    
    <?php endwhile; /* End the Loop */ ?>
    
    </ul>
    
    <div class="grid_12">
    <?php wp_pagenavi( array( 'query' => $my_query ) ); ?>
    </div>
  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Do you have more loops on that page? If this is a static front page you set the $paged argument like so:
    http://codex.wordpress.org/Pagination#static_front_page

  3. greencode
    Member
    Posted 2 years ago #

    Thanks for this. All I needed to do was to change this

    'paged' => get_query_var('paged')));

    to this

    'paged' => get_query_var('page')));

    in the above query.

Topic Closed

This topic has been closed to new replies.

About this Topic