Skip to content

Instantly share code, notes, and snippets.

@CyberStrike
Forked from ediamin/bootstrap-pagination.php
Last active May 17, 2017 03:26
Show Gist options
  • Save CyberStrike/e4dbc128eee0b11f21694eb6e5c66206 to your computer and use it in GitHub Desktop.
Save CyberStrike/e4dbc128eee0b11f21694eb6e5c66206 to your computer and use it in GitHub Desktop.
Bootstrap Pagination for WordPress
<?php
/*
* custom pagination with bootstrap .pagination class
* source: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
*/
function bootstrap_pagination( $custom_query = null, $echo = true ) {
global $wp_query;
$pagination = '';
$wpQuery = $custom_query ? $custom_query : $wp_query;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wpQuery -> max_num_pages,
'type' => 'array',
'prev_next' => true,
'prev_text' => __('&laquo; Prev'),
'next_text' => __('Next &raquo;'),
) );
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$pagination = '<ul class="pagination">';
foreach ( $pages as $page ) {
if ((strpos($page, 'prev') !== false) || strpos($page, 'next') !== false) {
$pieces = explode(" ", $page);
$pieces[1] = ' class="prev page-numbers page-link" ';
$pieces[2] = '';
$page = implode($pieces);
$pagination .= "<li class=\"page-item\">$page</li>";
} elseif (strpos($page, 'current') !== false){
$pieces = explode(" ", $page);
$pieces[0] .= ' ';
$pieces[1] .= ' page-link ';
$page = implode($pieces);
$pagination .= "<li class=\"page-item active\">$page</li>";
} else {
$pieces = explode(" ", $page);
$pieces[1] = ' class="prev page-numbers page-link" ';
$page = implode($pieces);
$pagination .= "<li class=\"page-item\">$page</li>";
}
}
$pagination .= '</ul>';
}
return $pagination;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment