Created
August 9, 2018 13:43
-
-
Save brianpurkiss/956c702de752f47e1d7c82ea5007a070 to your computer and use it in GitHub Desktop.
Plugin free numbered pagination for WordPress, uses Bootstrap styles
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
function numbered_pagination($pages = '', $range = 2) { | |
$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'><ul class='pagination'>"; | |
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li class='page-item'><a href='".get_pagenum_link(1)."' class='page-link'>«</a></li>"; | |
if($paged > 1 && $showitems < $pages) echo "<li class='page-item'><a href='".get_pagenum_link($paged - 1)."' class='page-link'>‹</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'><span class='current page-link disabled'>".$i."</span></li>":"<li class='page-item'><a href='".get_pagenum_link($i)."' class='page-link' >".$i."</a></li>"; | |
} | |
} | |
if ($paged < $pages && $showitems < $pages) echo "<li class='page-item'><a href='".get_pagenum_link($paged + 1)."' class='page-link'>›</a></li>"; | |
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li class='page-item'><a href='".get_pagenum_link($pages)."' class='page-link'>»</a></li>"; | |
echo "</ul></nav>\n"; | |
} | |
} | |
// insert onto archive page with: | |
// numbered_pagination(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment