Advertisement
leadbellydesign

WordPress Paginate Links Function

Aug 15th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <?php
  2. // http://codex.wordpress.org/Function_Reference/paginate_links
  3. //http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin/
  4. function pagination($pages = '', $range = 4)
  5. {  
  6.      $showitems = ($range * 2)+1;  
  7.  
  8.      global $paged;
  9.      if(empty($paged)) $paged = 1;
  10.  
  11.      if($pages == '')
  12.      {
  13.          global $wp_query;
  14.          $pages = $wp_query->max_num_pages;
  15.          if(!$pages)
  16.          {
  17.              $pages = 1;
  18.          }
  19.      }  
  20.  
  21.      if(1 != $pages)
  22.      {
  23.          echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  24.          if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  25.          if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
  26.  
  27.          for ($i=1; $i <= $pages; $i++)
  28.          {
  29.              if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  30.              {
  31.                  echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  32.              }
  33.          }
  34.  
  35.          if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";  
  36.          if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  37.          echo "</div>\n";
  38.      }
  39. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement