Same name and namespace in other branches
  1. 4.7.x includes/pager.inc \theme_pager_list()
  2. 5.x includes/pager.inc \theme_pager_list()

Format a list of nearby pages with additional query results.

Parameters

$limit: The number of query results to display per page.

$element: An optional integer to distinguish between multiple pagers on one page.

$quantity: The number of pages in the list.

$text: A string of text to display before the page list.

$attributes: An associative array of query string parameters to append to the pager links.

Return value

An HTML string that generates this piece of the query pager.

Related topics

1 theme call to theme_pager_list()
theme_pager in includes/pager.inc
Format a query pager.

File

includes/pager.inc, line 296
Functions to aid in presenting database results as a set of pages.

Code

function theme_pager_list($limit, $element = 0, $quantity = 5, $text = '', $attributes = array()) {
  global $pager_from_array, $pager_total;
  $output = '<div class="pager-list">';

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil((int) $quantity / 2);

  // offset adds "offset" second page
  $pager_offset = (int) $pager_from_array[$element] % (int) $limit;

  // current is the page we are currently paged to
  if (($pager_current = ceil(($pager_from_array[$element] + 1) / $limit)) < 1) {
    $pager_current = 1;
  }

  // first is the first page listed by this pager piece (re quantity)
  $pager_first = (int) $pager_current - (int) $pager_middle + 1;

  // last is the last page listed by this pager piece (re quantity)
  $pager_last = (int) $pager_current + (int) $quantity - (int) $pager_middle;

  // max is the maximum number of pages content can is divided into
  if (!($pager_max = ceil($pager_total[$element] / $limit))) {
    $pager_max = 1;
  }
  if ((int) $pager_offset) {

    // adjust for offset second page
    $pager_max++;
    $pager_current++;
  }

  // End of marker calculations.
  // Prepare for generation loop.
  $i = (int) $pager_first;
  if ($pager_last > $pager_max) {

    // Adjust "center" if at end of query.
    $i = $i + (int) ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {

    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }

  // End of generation loop preparation.
  // When there is more than one page, create the pager list.
  if ($i != $pager_max) {
    $output .= $text;
    if ($i > 1) {
      $output .= '<div class="pager-list-dots-left">... </div>';
    }

    // Now generate the actual pager piece.
    for (; $i <= $pager_last && $i <= $pager_max; $i++) {
      if ($i < $pager_current) {
        $output .= theme('pager_previous', $i, $limit, $element, $pager_current - $i, $attributes) . " ";
      }
      if ($i == $pager_current) {
        $output .= '<strong>' . $i . '</strong> ';
      }
      if ($i > $pager_current) {
        $output .= theme('pager_next', $i, $limit, $element, $i - $pager_current, $attributes) . " ";
      }
    }
    if ($i < $pager_max) {
      $output .= '<div class="pager-list-dots-right">...</div>';
    }
  }
  $output .= '</div>';
  return $output;
}