pagination

Pagination.

Description

pagination( (string) $pages = '', (int) $range = 2 ); 

Parameters (2)

0. $pages — Optional. (string) => ''
The pages.
1. $range — Optional. (int) => 2
The range.

Usage

  1. if ( !function_exists( 'pagination' ) ) { 
  2. require_once '/functions/inkthemes-functions.php'; 
  3.  
  4. // The pages. 
  5. $pages = ''; 
  6.  
  7. // The range. 
  8. $range = 2; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pagination($pages, $range); 
  12.  

Defined (1)

The function is defined in the following location(s).

/functions/inkthemes-functions.php  
  1. function pagination($pages = '', $range = 2) 
  2. {  
  3. $showitems = ($range * 2)+1;  
  4. global $paged; 
  5. if(empty($paged)) $paged = 1; 
  6. if($pages == '') 
  7. global $wp_query; 
  8. $pages = $wp_query->max_num_pages; 
  9. if(!$pages) 
  10. $pages = 1; 
  11. }  
  12. if(1 != $pages) 
  13. echo "<ul class='paging'>"; 
  14. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>«</a></li>"; 
  15. if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>‹</a></li>"; 
  16. for ($i=1; $i <= $pages; $i++) 
  17. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) 
  18. echo ($paged == $i)? "<li><a href='".get_pagenum_link($i)."' class='current' >".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>"; 
  19. if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>›</a></li>";  
  20. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>»</a></li>"; 
  21. echo "</ul>\n";