Pagination displaying two more pages than there really are.
-
Hey all,
I have created a simple theme using Twitter Bootstrap and am running into an issue with pagination. In every instance pagination shows up, it displays two more pages than actually exist (see example here: https://www.beerbitty.com/recipes/all/page/9/ — you’ll see an option for page 10 & 11, which don’t exist).
Here is the code I’ve used in functions.php to incorporate Bootstrap’s pagination (credit: https://www.lanexa.net/2012/09/add-twitter-bootstrap-pagination-to-your-wordpress-theme/)
function bootstrap_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 "<ul class='pagination pagination-centered'>"; /** Previous Post Link */ if ( get_previous_posts_link() ) printf( '<li>%s</li>' . "\n", get_previous_posts_link() ); 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 class='current'>".$i."</span></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>"; } } /** Next Post Link */ if ( get_next_posts_link() ) printf( '<li>%s</li>' . "\n", get_next_posts_link() ); echo "</ul>\n"; } }
I know it’s showing an additional 2 pages because $range = 2, but I’m wondering how to override that declaration when we’ve reached the end of pages.
Thanks in advance for your help!!
- The topic ‘Pagination displaying two more pages than there really are.’ is closed to new replies.