Easy Pagination In WordPress

Using the WP PageNavi Plugin (https://wordpress.org/plugins/wp-pagenavi/) you can easily achieve pagination in your theme. This plugin works right out of the box with the default settings.

Below is my archives.php template

 * Template Name: Archives Template

<?php get_header(); ?>

<div id="wrapper hentry">

  <div class="container">

    <div class="row push-down">
      <?php if ( function_exists('yoast_breadcrumb') ) {yoast_breadcrumb('<p id="breadcrumbs">','</p>');} ?>

      <div class="col-sm-8 special-page-bg">


          while($wp_query->have_posts()) : $wp_query->the_post(); ?>
            <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">

            <span><?php the_time('F j, Y'); ?></span><br/>

            <p class="entry-title"><a class="cta-link-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>


          <?php endwhile; ?>
          <?php wp_pagenavi(); ?>

          <?php wp_reset_postdata(); // reset the query ?>


      </div><!-- .col-sm-8 -->

            <?php get_sidebar(); ?>

    </div><!-- .row -->

  </div><!-- .container -->

</div><!-- .wrapper -->

<?php get_footer(); ?>

Just add the $paged variable to your wp_query():


Then add this right after your main loop before resetting your query:

    <?php wp_pagenavi(); ?>

That’s all it takes to get functional pagination. You can add css and style this any way you like and there are also options within the plugin settings to customize even further.