Skip to content

Instantly share code, notes, and snippets.

@sonnetmia
Created August 7, 2015 07:43
Show Gist options
  • Save sonnetmia/eb0514caabb635768f78 to your computer and use it in GitHub Desktop.
Save sonnetmia/eb0514caabb635768f78 to your computer and use it in GitHub Desktop.
Bootstrap pagination Code example
<?php
function arf_defaultpagination() {
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,
'prev_next' => false,
'type' => 'array',
'prev_next' => TRUE,
'prev_text' => '&larr; Previous',
'next_text' => 'Next &rarr;',
));
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>';
}
}
// Use arf_defaultpagination() function inside your query , Normally it placed after end of the while loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment