Skip to content

Instantly share code, notes, and snippets.

@shaunkrd
Created January 12, 2017 15:07
Show Gist options
  • Save shaunkrd/433588d01f0c135a8278823da58352a9 to your computer and use it in GitHub Desktop.
Save shaunkrd/433588d01f0c135a8278823da58352a9 to your computer and use it in GitHub Desktop.
Add pagination navigation to WordPress posts archive
<?php
$pages_required = $wp_query->max_num_pages;
// If $paged = 0 make it 1 for display below
if ($paged == 0) $paged = 1;
if ( $pages_required > 1 ) :
?>
<nav class="pagination">
<?php echo previous_posts_link( 'Newer', $pages_required ); ?>
<span class="pagination-indicator">Page <?php echo $paged; ?> of <?php echo $pages_required; ?></span>
<?php echo next_posts_link( 'Older', $pages_required ); ?>
</nav>
<?php endif; // END if ($pages_required > 1) ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment