I've been doing some pagination recently and used the following:
if ( $totalPages > $pagesToShow ) {
$start = $pageNumber - floor($pagesToShow/2);
$end = $pageNumber + floor($pagesToShow/2);
while ( $start < 1 ) {
$start++;
$end++;
}
while ( $end > $totalPages ) {
$start--;
$end--;
}
} else {
$start = 1;
$end = $totalPages;
}
to work out where to start and end the list of surrounding pages. So that a paging list can be created like << < 1 2 3 4 5 > >>'.
Just wondering if there is a better method as using loops like that seems a little odd.