Created
July 5, 2015 21:10
-
-
Save ediamin/52c942c62b00c5e3ebaa to your computer and use it in GitHub Desktop.
Bootstrap Pagination for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} | |
} | |
} |
Hello,
Made a slightly different version that :
- I tested with latest Bootstrap 4.1
- accept custom wp_query instance as argument (for custom wp_query()) or nothing to use global one
https://gist.github.com/mtx-z/f95af6cc6fb562eb1a1540ca715ed928
Another (2019, almost 2020 :) working example could be found here: https://gist.github.com/dvoracek-jakub/ce7ca24a15e4f77b5e67d827e9db6ed7
Thanks to OP!
Great job man!
Thanks dude
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obrigado!!!