Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

my_pagination

By: a guest on Feb 7th, 2013  |  syntax: PHP  |  size: 1.28 KB  |  views: 112  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function my_pagination($pages = '', $range = 2)
  2. {  
  3.      $showitems = ($range * 2)+1;  
  4.  
  5.      global $paged;
  6.      if(empty($paged)) $paged = 1;
  7.  
  8.      if($pages == '')
  9.      {
  10.          global $wp_query;
  11.          $pages = $wp_query->max_num_pages;
  12.          if(!$pages)
  13.          {
  14.              $pages = 1;
  15.          }
  16.      }  
  17.  
  18.      if(1 != $pages)
  19.      {
  20.          echo "<div class='pagination'>";
  21.          if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
  22.          if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
  23.  
  24.          for ($i=1; $i <= $pages; $i++)
  25.          {
  26.              if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  27.              {
  28.                  echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
  29.              }
  30.          }
  31.  
  32.          if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";  
  33.          if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
  34.          echo "</div>\n";
  35.      }
  36. }