1) {
$pageName = "?Keys=" . $keys . ($urlStr ?? '') . "&";
$pagelen = 3;
// First page and Previous page
if ($page > 1) {
echo "
首页";
echo "
上一页";
}
// Calculate page range
if ($pagelen * 2 + 1 >= $totalPages) {
$startPage = 1;
$endPage = $totalPages;
} else {
if ($page <= $pagelen + 1) {
$startPage = 1;
$endPage = $pagelen * 2 + 1;
} else {
$startPage = $page - $pagelen;
$endPage = $page + $pagelen;
}
if ($page + $pagelen > $totalPages) {
$startPage = $totalPages - $pagelen * 2;
$endPage = $totalPages;
}
}
// Page numbers
for ($i = $startPage; $i <= $endPage; $i++) {
if ($i == $page) {
echo "
{$i}";
} else {
echo "
{$i}";
}
}
// Next page and Last page
if ($page < $totalPages) {
if ($totalPages - $page > $pagelen) {
echo "
...{$totalPages}";
}
echo "
下一页";
echo "
尾页";
}
}
?>