Created
May 24, 2016 09:36
-
-
Save celticwebdesign/2c21dee698c2c2d700aa137c64d9737a to your computer and use it in GitHub Desktop.
Bootstrap pagination function
This file contains hidden or 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 | |
// http://fellowtuts.com/wordpress/bootstrap-3-pagination-in-wordpress/ | |
if (function_exists("wp_bs_pagination")) | |
{ | |
//wp_bs_pagination($the_query->max_num_pages); | |
wp_bs_pagination(); | |
} | |
?> | |
// Bootstrap pagination function | |
function wp_bs_pagination($pages = '', $range = 4) { | |
$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 '<div class="pagination-container"> | |
<div class="text-center">'; | |
echo '<nav> | |
<ul class="pagination">'; | |
// echo ' | |
// <li class="disabled hidden-xs"> | |
// <span> | |
// <span aria-hidden="true">Page '.$paged.' of '.$pages.'</span> | |
// </span> | |
// </li> | |
// '; | |
if($paged > 2 && $paged > $range+1 && $showitems < $pages) { | |
echo "<li> | |
<a href='".get_pagenum_link(1)."' aria-label='First'>«<span class='hidden-xs'> First</span></a> | |
</li>"; | |
} | |
if( $paged > 1 ) { | |
echo "<li> | |
<a href='".get_pagenum_link($paged - 1)."' aria-label='Previous'>‹<span class='hidden-xs'> Previous</span></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=\"active\"><span>".$i." <span class=\"sr-only\">(current)</span></span></li>":"<li><a href='".get_pagenum_link($i)."'>".$i."</a></li>"; | |
} | |
} | |
if ( $paged < $pages ) { | |
echo "<li><a href=\"".get_pagenum_link($paged + 1)."\" aria-label='Next'><span class='hidden-xs'>Next </span>›</a></li>"; | |
} | |
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) { | |
echo "<li><a href='".get_pagenum_link($pages)."' aria-label='Last'><span class='hidden-xs'>Last </span>»</a></li>"; | |
} | |
echo "</ul> | |
</nav>"; | |
echo "</div> | |
</div>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment