wp_pagenavi in Custom Blog Archive

I already read several answer in SE network and WP forum and several log. but I am still in the dark.
At first, I have to say, my consequence is different.

  • I created a Page Template Blog (blog.php) and added a wp_query on that page to show normal blog posts in that post because my homepage is a static homepage.
  • Then I simply created a blank page named Blog with permalink /blog
  • Next, I added wppagenavi on that ge after elsewhile
  • It didn’t work so I read couple of SOF answer and added
    <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
  • It shows page navigation but not working. I clicked 2,3,4… button and it return same page though url changes to /blog/page/2

So, how to make page navi work?
My snippet

 <?php $the_query = new WP_Query( 'showposts=8' ); ?>

    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="content-box bg-wrap"><?php 
if ( has_post_thumbnail() ) { ?>
<div class="img"><a href="<?php the_permalink(); ?>">
    the_post_thumbnail( 'blog_thumb' );
<div class="post-info p20px">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="post-meta"><span class="theauthor"><i class="fa fa-user"></i> <?php echo get_the_author(); ?></span> <span class="thetime"><i class="fa fa-clock-o"></i> <?php the_date(); ?></span> <span class="thecategory"><i class="fa fa-tags"></i><?php the_category(', '); ?></span> <span class="thecomments"><i class="fa fa-comments"></i><?php echo $write_comments; ?></span> </div>
<?php echo substr(get_the_excerpt(), 0,600); ?> <a href="<?php the_permalink(); ?>">Read this post &raquo;</a>
    <?php endwhile;?>
    <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>

Do not bother other functions and variables or html. I just need to make pagenavi work.
I got pagenavi code from here

Source: wordpress

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.