nggNavigation

NggNavigation - PHP class for the pagination.

Defined (1)

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

/lib/navigation.php  
  1. class nggNavigation { 
  2.  
  3. /** 
  4. * Return the navigation output 
  5. * @access public 
  6. * @var string 
  7. */ 
  8. var $output = false; 
  9.  
  10. /** 
  11. * Link to previous page 
  12. * @access public 
  13. * @var string 
  14. */ 
  15. var $prev = false; 
  16.  
  17. /** 
  18. * Link to next page 
  19. * @access public 
  20. * @var string 
  21. */ 
  22. var $next = false; 
  23.  
  24. /** 
  25. * Main constructor - Does nothing. 
  26. * Call create_navigation() method when you need a navigation. 
  27. *  
  28. */  
  29. function __construct() { 
  30. return;  
  31.  
  32. /** 
  33. * nggNavigation::create_navigation() 
  34. *  
  35. * @param mixed $page 
  36. * @param integer $totalElement  
  37. * @param integer $maxElement 
  38. * @return string pagination content 
  39. */ 
  40. function create_navigation($page, $totalElement, $maxElement = 0) { 
  41. global $nggRewrite; 
  42.  
  43. $prev_symbol = apply_filters('ngg_prev_symbol', '◄'); 
  44. $next_symbol = apply_filters('ngg_prev_symbol', '►'); 
  45.  
  46. if ($maxElement > 0) { 
  47. $total = $totalElement; 
  48.  
  49. // create navigation  
  50. if ( $total > $maxElement ) { 
  51. $total_pages = ceil( $total / $maxElement ); 
  52. $r = ''; 
  53. if ( 1 < $page ) { 
  54. $args['nggpage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1; 
  55. $previous = $args['nggpage']; 
  56. if (FALSE == $args['nggpage']) { 
  57. $previous = 1;  
  58. $this->prev = $nggRewrite->get_permalink ( $args ); 
  59. $r .= '<a class="prev" id="ngg-prev-' . $previous . '" href="' . $this->prev . '">' . $prev_symbol . '</a>'; 
  60.  
  61. $total_pages = ceil( $total / $maxElement ); 
  62.  
  63. if ( $total_pages > 1 ) { 
  64. for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) { 
  65. if ( $page == $page_num ) { 
  66. $r .= '<span class="current">' . $page_num . '</span>'; 
  67. } else { 
  68. $p = false; 
  69. if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) { 
  70. $args['nggpage'] = ( 1 == $page_num ) ? FALSE : $page_num; 
  71. $r .= '<a class="page-numbers" href="' . $nggRewrite->get_permalink( $args ) . '">' . ( $page_num ) . '</a>'; 
  72. $in = true; 
  73. } elseif ( $in == true ) { 
  74. $r .= '<span class="more">...</span>'; 
  75. $in = false; 
  76.  
  77. if ( ( $page ) * $maxElement < $total || -1 == $total ) { 
  78. $args['nggpage'] = $page + 1; 
  79. $this->next = $nggRewrite->get_permalink ( $args ); 
  80. $r .= '<a class="next" id="ngg-next-' . $args['nggpage'] . '" href="' . $this->next . '">' . $next_symbol . '</a>'; 
  81.  
  82. $this->output = "<div class='ngg-navigation'>$r</div>"; 
  83. } else { 
  84. $this->output = "<div class='ngg-clear'></div>"."\n"; 
  85.  
  86. return $this->output;