I've got a custom loop for which I'd like pagination.
The codex and examples I've found online indicate that I should get pagination as long as I pass the 'paged' query variable into the loop as the 'page' variable ( or 'page' for a static front page). However in my case this simply doesn't work.
I'm not working with a static front page: just a normal Page.
What I'm seeing is that for every page that I navigate to, I get the same posts.
This is the template I'm working with:
<div class="container latest-posts group">
<div class="row">
<div class="container">
<header class="section-header row">
<div class="col-xs-12">
<h2 "><?php the_title() ?></h2>
</div>
</header>
</div>
<section id="latest-posts" class="col col-xs-12 col-sm-8 js-masonry">
<?php
/*
* latest posts
*/
if ( get_query_var('paged') ) $paged = get_query_var('paged');
if ( get_query_var('page') ) $paged = get_query_var('page');
$args = array(
'posts_per_page' => 7,
'offset' => '5',
'paged' => $paged
) ;
$my_query = new WP_Query($args) ;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<article class="frontpage-news-article">
<div class="inner">
<h3>
<a href="<?php the_permalink() ?>">
<?php the_title() ?>
</a>
</h3>
<?php include( get_stylesheet_directory() . "/templates/post-meta.php") ; ?>
<p><?php the_excerpt(); ?></p>
<p><a href="<?php echo get_permalink() ?>">read more</a></p>
</div>
</article>
<?php endwhile; ?>
<?php
// Reset postdata
wp_reset_postdata();
?>
<footer class="paging group">
<?php next_posts_link('« Older Entries') ?>
<?php previous_posts_link('Newer Entries »') ?>
<?php
wp_pagenavi( array(
'query' =>$my_query )
)
?>
</footer>
</section> <!-- ENDS #latest-posts -->
<aside class="sidebar col-xs-12 col-sm-4 group" role="complementary">
<ul>
<?php dynamic_sidebar('primary') ?>
</ul>
</aside><!-- .sidebar -->
<?php
?>
</div> <!-- ENDS .container -->
</div>
As you can by the code, I've been trying both wordpress's native pagination calls and also wp-pagenavi. Both of them yield the same undesirable results.