我有分页问题,如何只显示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.
?>
答案 0 :(得分: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
我希望这对你有用。
答案 1 :(得分: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++) {
答案 2 :(得分:0)
<?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.
?>