Advertisement
Guest User

pagination function

a guest
Aug 31st, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. /*inserts custom page/post navigation at the bottom of posts */
  2. function blah_pagination($pages = '', $range = 1) {   /* handle pagination for post pages*/
  3.     $showitems = ($range * 1)+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\"><span>Page ".$paged." of ".$pages."</span>";
  21.             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  22.             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</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)."\">Next &rsaquo;</a>";
  33.             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  34.             echo "</div>\n";
  35.         }
  36.     } //  blah_pagination
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement