ebow

Pagination function

Oct 29th, 2018
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // Function uses Bootstrap mark-up for pagination, cf. https://fellowtuts.com/bootstrap/wordpress-pagination-bootstrap-4-style/
  4.  
  5. function fellowtuts_wpbs_pagination($pages = '', $range = 7) // Sets number of numbers to use in paginator
  6. {
  7.  $showitems = ($range * 2) + 1;
  8.  global $paged;
  9.  if(empty($paged)) $paged = 1;
  10.  if($pages == '')
  11.  {
  12.  global $wp_query;
  13.  $pages = $wp_query->max_num_pages;
  14.  
  15.  if(!$pages)
  16.  $pages = 1;
  17.  }
  18.  
  19.  if(1 != $pages)
  20.  {
  21.      echo '<nav aria-label="Page navigation" role="navigation" class="pt-2">';
  22.         echo '<span class="sr-only">Page navigation</span>';
  23.         echo '<ul class="pagination justify-content-center ft-wpbs">';
  24.  
  25.         echo '<li class="page-item disabled hidden-md-down d-none d-lg-block"><span class="page-link">Page '.$paged.' of '.$pages.'</span></li>';
  26.  
  27.  if($paged > 2 && $paged > $range+1 && $showitems < $pages)
  28.  echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link(1).'" aria-label="First Page">&laquo;</a></li>';
  29.  
  30.  if($paged > 1 && $showitems < $pages)
  31.  echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($paged - 1).'" aria-label="Previous Page">&lsaquo;</a></li>';
  32.  
  33.  for ($i=1; $i <= $pages; $i++)
  34.  {
  35.      if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  36.  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>';
  37.  }
  38.  
  39.  if ($paged < $pages && $showitems < $pages)
  40.  echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($paged + 1).'" aria-label="Next Page">&rsaquo;</a></li>';
  41.  
  42.  if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages)
  43.  echo '<li class="page-item"><a class="page-link" href="'.get_pagenum_link($pages).'" aria-label="Last Page">&raquo;</a></li>';
  44.  
  45.  echo '</ul>';
  46.         echo '</nav>';
  47.         // echo '<div class="pagination-info mb-5 text-center">[ <span class="text-muted">Page</span> '.$paged.' <span class="text-muted">of</span> '.$pages.' ]</div>';
  48.  }
  49. }
  50.  
  51. ?>
RAW Paste Data