When using theme_pager, the function will set $pager_last one too high when the user is on the last page.

Suppose you call theme('pager', $tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 3). Note that $quantity is an odd number.

When the user is on the first page, the values for $pager_middle and $pager_last are set as follows (values are in brackets):
$pager_middle(2) = ceil($quantity(3) / 2)
$pager_last(2) = $pager_current(1) + $quantity(3) - $pager_middle(2)
//$pager_last is 2, not a problem

On the second page (page=1 in the url)
$pager_middle(2) = ceil($quantity(3) / 2)
$pager_last(3) = $pager_current(2) + $quantity(3) - $pager_middle(2)
//$pager_last is 3, correct

On the third and last page (page=2 in the url)
$pager_middle(2) = ceil($quantity(3) / 2)
$pager_last(4) = $pager_current(3) + $quantity(3) - $pager_middle(2)

Now $pager_last is 4, ai!, pager will now generate a link to page 4 which contains nothing. And on page 4, the pager will generate a link to page 5, which also contains nothing.

Comments

steven jones’s picture

Status: Active » Closed (works as designed)

Actually looking at the code for theme_pager there is a code block after the section you have outlined:


// Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($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;
  }

that takes care of the case when the $pager_last > $pager_max, so as long as your pager is being set up correctly, the core pager code should work just fine.