Skip to content

Instantly share code, notes, and snippets.

@lkhedlund
Forked from ediamin/bootstrap-pagination.php
Last active September 5, 2017 21:30
Show Gist options
  • Save lkhedlund/27fee91e0d3b40c1bcc1ac56cb15541f to your computer and use it in GitHub Desktop.
Save lkhedlund/27fee91e0d3b40c1bcc1ac56cb15541f to your computer and use it in GitHub Desktop.
Bootstrap v4-alpha6 Pagination for WordPress
/*
* custom pagination with bootstrap .pagination class
* source: http://www.ordinarycoder.com/paginate_links-class-ul-li-bootstrap/
*/
function bootstrap_pagination( $echo = true ) {
global $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' => $wp_query->max_num_pages,
'type' => 'array',
'prev_next' => true,
'prev_text' => __('« Prev'),
'next_text' => __('Next »'),
)
);
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
$pagination = '<ul class="pagination">';
foreach ( $pages as $page ) {
$pagination .= "<li>$page</li>";
}
$pagination .= '</ul>';
if ( $echo ) {
echo $pagination;
} else {
return $pagination;
}
}
}
@brettalton
Copy link

brettalton commented Sep 5, 2017

I don't see the pagination formatting working because the data in $page can not be edited to add the requiredclass="page-link" to the <a> anchor element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment