Fix for theme_pager

  1. /**
  2.  * Format a query pager.
  3.  *
  4.  * Menu callbacks that display paged query results should call theme('pager') to
  5.  * retrieve a pager control so that users can view other results.
  6.  * Format a list of nearby pages with additional query results.
  7.  *
  8.  * @param $tags
  9.  *   An array of labels for the controls in the pager.
  10.  * @param $limit
  11.  *   The number of query results to display per page.
  12.  * @param $element
  13.  *   An optional integer to distinguish between multiple pagers on one page.
  14.  * @param $parameters
  15.  *   An associative array of query string parameters to append to the pager links.
  16.  * @param $quantity
  17.  *   The number of pages in the list.
  18.  * @return
  19.  *   An HTML string that generates the query pager.
  20.  *
  21.  * @ingroup themeable
  22.  */
  23. function mytheme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  24.   global $pager_page_array, $pager_total;
  25.  
  26.   // Calculate various markers within this pager piece:
  27.   // Middle is used to "center" pages around the current page.
  28.   $pager_middle = ceil($quantity / 2);
  29.   // current is the page we are currently paged to
  30.   $pager_current = $pager_page_array[$element] + 1;
  31.   // first is the first page listed by this pager piece (re quantity)
  32.   $pager_first = $pager_current - $pager_middle + 1;
  33.   // last is the last page listed by this pager piece (re quantity)
  34.   $pager_last = $pager_current + $quantity - $pager_middle;
  35.   // max is the maximum page number
  36.   $pager_max = $pager_total[$element];
  37.   // End of marker calculations.
  38.  
  39.   // Prepare for generation loop.
  40.   $i = $pager_first;
  41.   if ($pager_last > $pager_max) {
  42.     // Adjust "center" if at end of query.
  43.     $i = $i + ($pager_max - $pager_last);
  44.     $pager_last = $pager_max;
  45.   }
  46.   if ($i <= 0) {
  47.     // Adjust "center" if at start of query.
  48.     $pager_last = $pager_last + (1 - $i);
  49.     $i = 1;
  50.   }
  51.   // End of generation loop preparation.
  52.  
  53.   $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
  54.   $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
  55.   $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);
  56.   $li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters);
  57.  
  58.   if ($pager_total[$element] > 1) {
  59.     if ($li_first) {
  60.       $items[] = array(
  61.         'class' => 'pager-first',
  62.         'data' => $li_first,
  63.       );
  64.     }
  65.     if ($li_previous) {
  66.       $items[] = array(
  67.         'class' => 'pager-previous',
  68.         'data' => $li_previous,
  69.       );
  70.     }
  71.  
  72.     // When there is more than one page, create the pager list.
  73.     if ($i != $pager_max) {
  74.       if ($i > 1) {
  75.         $items[] = array(
  76.           'class' => 'pager-ellipsis',
  77.           'data' => '…',
  78.         );
  79.       }
  80.       // Now generate the actual pager piece.
  81.       for (; $i <= $pager_last && $i <= $pager_max; $i++) {
  82.         if ($i < $pager_current) {
  83.           $items[] = array(
  84.             'class' => 'pager-item',
  85.             'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
  86.           );
  87.         }
  88.         if ($i == $pager_current) {
  89.           $items[] = array(
  90.             'class' => 'pager-current',
  91.             'data' => $i,
  92.           );
  93.         }
  94.         if ($i > $pager_current) {
  95.           $items[] = array(
  96.             'class' => 'pager-item',
  97.             'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
  98.           );
  99.         }
  100.       }
  101.       if ($i < $pager_max) {
  102.         $items[] = array(
  103.           'class' => 'pager-ellipsis',
  104.           'data' => '…',
  105.         );
  106.       }
  107.     }
  108.     // End generation.
  109.     if ($li_next) {
  110.       $items[] = array(
  111.         'class' => 'pager-next',
  112.         'data' => $li_next,
  113.       );
  114.     }
  115.     if ($li_last) {
  116.       $items[] = array(
  117.         'class' => 'pager-last',
  118.         'data' => $li_last,
  119.       );
  120.     }
  121.     return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  122.   }
  123. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.