Advertisement
Guest User

my_pagination

a guest
Feb 7th, 2013
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement