Pager D6 < 1 ... 5 6 7 8 9 ... 15 >

Public

insert into settings.php

Get raw version
php
  1. function yourtheme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
  2. global $pager_page_array, $pager_total;
  3. $tags = array("", "<", "", ">", "");
  4.  
  5. // Calculate various markers within this pager piece:
  6. // Middle is used to "center" pages around the current page.
  7. $pager_middle = ceil($quantity / 2);
  8.  
  9. // current is the page we are currently paged to
  10. $pager_current = $pager_page_array[$element] + 1;
  11.  
  12. // first is the first page listed by this pager piece (re quantity)
  13. $pager_first = $pager_current - $pager_middle + 1;
  14.  
  15. // last is the last page listed by this pager piece (re quantity)
  16. $pager_last = $pager_current + $quantity - $pager_middle;
  17.  
  18. // max is the maximum page number
  19. $pager_max = $pager_total[$element];
  20.  
  21. // End of marker calculations.
  22.  
  23. // Prepare for generation loop.
  24. $i = $pager_first;
  25. if ($pager_last > $pager_max) {
  26. // Adjust "center" if at end of query.
  27. $i = $i + ($pager_max - $pager_last);
  28. $pager_last = $pager_max;
  29. }
  30. if ($i <= 0) {
  31. // Adjust "center" if at start of query.
  32. $pager_last = $pager_last + (1 - $i);
  33. $i = 1;
  34. }
  35. // End of generation loop preparation.
  36.  
  37. $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
  38. $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);
  39.  
  40. //print theme('pager_previous', $output, $limit, $element, 1, $parameters);
  41.  
  42.  
  43. if ($pager_total[$element] > 1) {
  44.  
  45. if ($li_previous) {
  46. $items[] = array(
  47. 'class' => 'pager-previous',
  48. 'data' => $li_previous,
  49. );
  50. if($pager_current >= ($quantity -1) ){
  51. $items[] = array(
  52. 'class' => 'pager-item',
  53. 'data' => theme('pager_previous', 1, $limit, $element, ($pager_current - 1), $parameters),
  54. );
  55. if($pager_current >= $quantity ){
  56. $items[] = array(
  57. 'class' => 'disabled',
  58. 'data' => '<span>...</span>',
  59. );
  60. }
  61. }
  62. }
  63.  
  64. // When there is more than one page, create the pager list.
  65. if ($i != $pager_max) {
  66. // Now generate the actual pager piece.
  67. for (; $i <= $pager_last && $i <= $pager_max; $i++) {
  68. if ($i < $pager_current) {
  69.  
  70. if ($pager_first > 1 && $i == $pager_first) {
  71.  
  72. $output = $i;
  73.  
  74. } else {
  75. $output = $i;
  76. }
  77. $items[] = array(
  78. 'class' => 'pager-item',
  79. 'data' => theme('pager_previous', $output, $limit, $element, ($pager_current - $i), $parameters),
  80. );
  81. }
  82. if ($i == $pager_current) {
  83. $items[] = array(
  84. 'class' => 'disabled',
  85. 'data' => '<a href="#">'.$i.'</a>',
  86. );
  87. }
  88. if ($i > $pager_current) {
  89.  
  90. if ($pager_last < $pager_max && $i == $pager_last) {
  91.  
  92.  
  93.  
  94. $output = $i;
  95.  
  96. } else {
  97. $output = $i;
  98. }
  99.  
  100.  
  101. $items[] = array(
  102. 'class' => 'pager-item',
  103. 'data' => theme('pager_next', $output, $limit, $element, ($i - $pager_current), $parameters),
  104. );
  105. }
  106. }
  107. }
  108. // End generation.
  109. if ($li_next) {
  110. if($pager_current < ($pager_max - ($quantity/2)) ){
  111. if($pager_current <= ($pager_max - ($quantity -1)) ){
  112. $items[] = array(
  113. 'class' => 'disabled',
  114. 'data' => '<span>...</span>',
  115. );
  116. }
  117.  
  118. $items[] = array(
  119. 'class' => 'pager-item',
  120. 'data' => theme('pager_previous', $pager_max, $limit, $element, ($pager_current - $pager_max), $parameters),
  121. );
  122.  
  123.  
  124. }
  125. $items[] = array(
  126. 'class' => 'pager-next',
  127. 'data' => $li_next,
  128. );
  129. }
  130.  
  131. return theme('item_list', $items, NULL, 'ul', array('class' => 'pagination'));
  132. }
  133. }