hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// 上一页 1 2 3 4 5...525 下一页
// 上一页 1...3 4 5 6 7...525 下一页
// 上一页 1...4 5 6 7 8...525 下一页
// 上一页 1...518 519 520 521 522...525 下一页
// 上一页 1...520 521 522 523 524 525 下一页
$centerButtonCount = 9; // 修改此配置即可,建议奇数
$totalPage = intval($totalCount / $limit + ($totalCount % $limit > 0 ? 1 : 0));
// $totalPage = 100;
// $page = 50;
 
if ($totalPage <= 0) {
    exit;
}
 
if ($page > $totalPage) {
    $page = $totalPage;
}
if ($page < 1) {
    $page = 1;
}
$showPageButtonNumArray = array();
if ($totalPage <= $centerButtonCount + 2) {
    $showPageButtonNumArray += range(1, $totalPage);
} else {
    $halfButtonNum = intval($centerButtonCount / 2);
    if ($page <= $halfButtonNum) {
        $centerButtonNumArray = range(2, $centerButtonCount);
    } else if ($page + $halfButtonNum < $totalPage) {
        $centerButtonNumArray = range($page - $halfButtonNum, $page + $halfButtonNum);
    } else {
        $centerButtonNumArray = range($totalPage - $centerButtonCount, $totalPage);
    }
    if ($centerButtonNumArray[0] > 1) {
        array_push($showPageButtonNumArray, 1);
    }
    if ($centerButtonNumArray[0] > 2) {
        array_push($showPageButtonNumArray, "");
    }
    $showPageButtonNumArray  = array_merge($showPageButtonNumArray, $centerButtonNumArray);
    if ($centerButtonNumArray[count($centerButtonNumArray) - 1] < $totalPage - 1) {
        array_push($showPageButtonNumArray, "");
    }
    if ($centerButtonNumArray[count($centerButtonNumArray) - 1] < $totalPage) {
        array_push($showPageButtonNumArray, $totalPage);
    }
}
echo "<hr />";
echo "<center>";
echo "<input type=\"submit\" id=\"prepage\" value=\"" . \Lang\gettext("上一页") . "\" onclick=\"return changePage('" . ($page - 1) . "')\"";
if ($page == 1) {
    echo " disabled=\"true\"";
}
echo "/>";
for ($i = 0; $i < count($showPageButtonNumArray); $i++) {
    $p = $showPageButtonNumArray[$i];
    if ($p == "") {
        echo "&nbsp...";
        continue;
    }
    echo "&nbsp;<input type=\"submit\" id=\"page" . $p . "\" value=\"" . $p . "\" onclick=\"return changePage('" . $p . "')\"";
    if ($p == $page) {
        echo " class=\"button green medium\" disabled=\"true\"";
    }
    echo "/>";
}
echo "&nbsp;<input type=\"submit\" id=\"nextpage\" value=\"" . \Lang\gettext("下一页") . "\" onclick=\"return changePage('" . ($page + 1) . "')\"";
if ($page == $totalPage) {
    echo " disabled=\"true\"";
}
echo "/>";
echo "&nbsp;<input type=\"number\" name=\"topage\" id=\"topage\" value=\"\" min=\"1\" max=\"" . $totalPage . "\" style=\"width: 60px\" />";
echo "&nbsp;<input type=\"submit\" value=\"" . \Lang\gettext("跳转") . "\" />";
echo "</center>";
echo "&nbsp;<input type=\"hidden\" name=\"page\" id=\"page\" value=\"\"/>";
?>
<script type="text/javascript">
    function changePage(page) {
        document.getElementById("topage").value = "";
        document.getElementById("page").value = page;
        return true;
    }
</script>