Forked from mishalrai/WP-bootstrap-pagination.php
Last active
April 17, 2018 11:37
-
-
Save ashokmhrj/9f9cd2760beebadc2bb0670cbe271f2b to your computer and use it in GitHub Desktop.
Wordpress pagination with bootstrap pagination design
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
<?php | |
/** | |
* Wordpress pagination | |
* paginate_links | |
* https://codex.wordpress.org/Function_Reference/paginate_links | |
*/ | |
function wp_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 justify-content-center">'; | |
foreach ($pages as $page) { | |
$page = preg_replace('|page-numbers|','page-link', $page ); | |
$pagination .= '<li class="page-item ' . ( strrpos($page, 'current') ? 'active' :'') . ' ">'.$page.'</li>'; | |
} | |
$pagination .= '</ul>'; | |
if ($echo) { | |
echo $pagination; | |
} else { | |
return $pagination; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment