Skip to content

Instantly share code, notes, and snippets.

@ssbalakumar
Created April 22, 2017 09:39
Show Gist options
  • Save ssbalakumar/19086295dee2518ec43ce34fe8e4e935 to your computer and use it in GitHub Desktop.
Save ssbalakumar/19086295dee2518ec43ce34fe8e4e935 to your computer and use it in GitHub Desktop.
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function thunderwp_pagination()
{
global $wp_query;
$big = 999999999;
$pages = paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_next' => TRUE,
'prev_text' => '← Previous',
'next_text' => 'Next →',
));
if (is_array($pages)) {
$current_page = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<ul class="pagination">';
foreach ($pages as $i => $page) {
if ($current_page == 1 && $i == 0) {
echo "<li class='active'>$page</li>";
} else {
if ($current_page != 1 && $current_page == $i) {
echo "<li class='active'>$page</li>";
} else {
echo "<li>$page</li>";
}
}
}
echo '</ul>';
}
}
Output:
------
<div class="container text-center">
<div class="row">
<div class="col-md-12">
<div class="pagination">
<?php thunderwp_pagination(); ?>
</div>
</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment