Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Function uses Bootstrap mark-up for pagination, cf. https://fellowtuts.com/bootstrap/wordpress-pagination-bootstrap-4-style/
- function fellowtuts_wpbs_pagination($pages = '', $range = 7) // Sets number of numbers to use in paginator
- {
- $showitems = ($range * 2) + 1;
- global $paged;
- if(empty($paged)) $paged = 1;
- if($pages == '')
- {
- global $wp_query;
- $pages = $wp_query->max_num_pages;
- if(!$pages)
- $pages = 1;
- }
- if(1 != $pages)
- {
- echo '<nav aria-label="Page navigation" role="navigation" class="pt-2">';
- echo '<span class="sr-only">Page navigation</span>';
- echo '<ul class="pagination justify-content-center ft-wpbs">';
- echo '<li class="page-item disabled hidden-md-down d-none d-lg-block"><span class="page-link">Page '.$paged.' of '.$pages.'</span></li>';
- if($paged > 2 && $paged > $range+1 && $showitems < $pages)
- echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link(1).'" aria-label="First Page">«</a></li>';
- if($paged > 1 && $showitems < $pages)
- echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($paged - 1).'" aria-label="Previous Page">‹</a></li>';
- for ($i=1; $i <= $pages; $i++)
- {
- if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
- echo ($paged == $i)? '<li class="page-item active"><span class="page-link">'.$i.'</span></li>' : '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($i).'"><span class="sr-only">Page </span>'.$i.'</a></li>';
- }
- if ($paged < $pages && $showitems < $pages)
- echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($paged + 1).'" aria-label="Next Page">›</a></li>';
- if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages)
- echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($pages).'" aria-label="Last Page">»</a></li>';
- echo '</ul>';
- echo '</nav>';
- // echo '<div class="pagination-info mb-5 text-center">[ <span class="text-muted">Page</span> '.$paged.' <span class="text-muted">of</span> '.$pages.' ]</div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement