3

我的分页有问题,如何只显示 10 个项目?可以在谷歌做这样的事情 - 数字增加了+5?

在此处输入图像描述

<?php
// Make the links to other pages, if necessary.
if ($pages > 1) {

    echo '<br /><p>';
    $current_page = ($start/$display) + 1;

    // If it's not the first page, make a Previous button:
    if ($current_page != 1) {
        echo '<a href="list_photos_4.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
    }

    // Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $current_page) {
            echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop.

    // If it's not the last page, make a Next button:
    if ($current_page != $pages) {
        echo '<a href="list_photos_4.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
    }

    echo '</p>'; // Close the paragraph.

} // End of links section.
?>
4

3 回答 3

2

尝试将部分(制作所有编号的页面)更改为:

// Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {    
        if ($i != $current_page) {
            $distance = $current_page - $i;
            if (abs($distance) < 5){
                echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
            } 
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop

我希望这对你有用。

于 2013-10-15T10:15:17.040 回答
1
<?php
// Make the links to other pages, if necessary.
if ($pages > 1) {

    // (...)

    $first_disp_page = $cutrrent_page - 5 < 1 ? 1 : $current_page - 5;
    $last_disp_page = $current_page + 5 > $pages ? $pages : $current_page + 5;

    // Make all the numbered pages:
    for ($i = $first_disp_page; $i <= $last_disp_page; $i++) {
        if ($i != $current_page) {
            echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop.

    // (...)

} // End of links section.
?>
于 2013-10-15T10:15:00.807 回答
0

改变这个:

// Make all the numbered pages:
for ($i = 1; $i <= $pages; $i++) {

对此:

if ($current_page <= 5) $first_page = 1;
else if ($pages - $current_page < 10) $first_page = $pages - 10;
else $first_page = $current_page - 5;

// Make up to 10 numbered pages:
for ($i = $first_page; $i < ($first_page + 10); $i++) {
于 2013-10-15T10:14:22.053 回答