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
Comment #1
steven jones commentedActually looking at the code for
theme_pagerthere is a code block after the section you have outlined: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.