yit_pagination

Print pagination.

Description

(string) yit_pagination( (string) $pages = '', (int) $range = 10 ); 

Returns (string)

Parameters (2)

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

Usage

  1. if ( !function_exists( 'yit_pagination' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-compare/plugin-fw/yit-functions.php'; 
  3.  
  4. // The pages. 
  5. $pages = ''; 
  6.  
  7. // The range. 
  8. $range = 10; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = yit_pagination($pages, $range); 
  12.  

Defined (1)

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

/plugin-fw/yit-functions.php  
  1. function yit_pagination ( $pages = '', $range = 10 ) { 
  2. $showitems = ( $range * 2 ) + 1; 
  3.  
  4. $paged = ( get_query_var ( 'paged' ) ) ? get_query_var ( 'paged' ) : false; 
  5. if ( $paged === false ) { 
  6. $paged = ( get_query_var ( 'page' ) ) ? get_query_var ( 'page' ) : false; 
  7. if ( $paged === false ) { 
  8. $paged = 1; 
  9.  
  10.  
  11. $html = ''; 
  12.  
  13. if ( $pages == '' ) { 
  14. global $wp_query; 
  15.  
  16. if ( isset( $wp_query->max_num_pages ) ) { 
  17. $pages = $wp_query->max_num_pages; 
  18.  
  19. if ( ! $pages ) { 
  20. $pages = 1; 
  21.  
  22. if ( 1 != $pages ) { 
  23. $html .= "<div class='general-pagination clearfix'>"; 
  24. if ( $paged > 2 ) { 
  25. $html .= sprintf ( '<a class="%s" href="%s">«</a>', 'yit_pagination_first', get_pagenum_link ( 1 ) ); 
  26. if ( $paged > 1 ) { 
  27. $html .= sprintf ( '<a class="%s" href="%s">‹</a>', 'yit_pagination_previous', get_pagenum_link ( $paged - 1 ) ); 
  28.  
  29. for ( $i = 1; $i <= $pages; $i ++ ) { 
  30. if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) { 
  31. $class = ( $paged == $i ) ? " class='selected'" : ''; 
  32. $html .= "<a href='" . get_pagenum_link ( $i ) . "'$class >$i</a>"; 
  33.  
  34. if ( $paged < $pages ) { 
  35. $html .= sprintf ( '<a class="%s" href="%s">›</a>', 'yit_pagination_next', get_pagenum_link ( $paged + 1 ) ); 
  36. if ( $paged < $pages - 1 ) { 
  37. $html .= sprintf ( '<a class="%s" href="%s">»</a>', 'yit_pagination_last', get_pagenum_link ( $pages ) ); 
  38.  
  39. $html .= "</div>\n"; 
  40.  
  41. echo apply_filters ( 'yit_pagination_html', $html );