Truncate number of pages in pagination(截断分页中的页数)
问题描述
这可能是一个非常愚蠢的问题,但我想不出任何可以帮助我走得更远的东西.我希望缩短页面导航中 NUMBERS 的数量.
而不是像:1, 2, 3, 4, 5, 6, 7, 8
我希望它是这样的:1, 2...7, 8
当我转到 2 时,数字 3 现在应该会出现在数字组中.
这是我负责页码的代码:
这是我为分页论坛编写的修改后的代码块.
它的输出并不完全是你展示的方式,而应该只是调整的问题.
<?php if ($numPages > 1): ?><li>Page <?php echo $currentPage?><?php echo $numPages?></li><?php if ($currentPage > 1): ?><li><a href="imgit_images.php?page=1">首先</a></li><li><a href="imgit_images.php?page=<?php echo $currentPage-1?>"><</a></li><?php endif;?><?php if ($currentPage > $howMany + 1): ?><li>...</li><?php endif;?><?php for ($pageIndex = $currentPage - $howMany; $pageIndex <= $currentPage + $howMany; $pageIndex++): ?><?php if ($pageIndex >= 1 && $pageIndex <= $numPages): ?><li><?php if ($pageIndex == $currentPage): ?><你><?php endif;?><a href="imgit_images.php?page=<?php echo $pageIndex?>"><?php echo $pageIndex?></a><?php if ($pageIndex == $currentPage): ?></u><?php endif;?><?php endif;?><?php endfor;?><?php if ($currentPage < $numPages - $howMany): ?><li>...</li><?php endif;?><?php if ($currentPage < $numPages): ?><li><a href="imgit_images.php?page=<?php echo $currentPage+1?>">></a></li><li><a href="imgit_images.php?page=-1">最后</a></li><?php endif;?><?php endif;?>
This might be a quite silly question, but I can't figure anything out that might help me go further. I'm looking to shorten the number of NUMBERS in my page navigation.
Instead of being like: 1, 2, 3, 4, 5, 6, 7, 8
I want it be like: 1, 2...7, 8
And when I go to 2, number 3 should now be seen in the numbers group.
Here is my code that is in charge of the page numbers:
<div id="user_nav_bottom">
<?php for($i=1; $i < sizeof($pages)+1; $i++) {
$strong = ($_GET['page'] == $i) ? ' dark bold' : '';
echo '<span class="normal' . $strong . '"><a href="imgit_images.php?page=' . $i . '">' . $i . ', </a></span>';
} ?>
</div>
This is a modified chunk of code I wrote for paging forums.
It's output isn't exactly how you showed but should just be a matter of tweaking.
<?php
//Set up vars
$currentPage = isset($_GET["page"])? $_GET["page"] : 1;
$numPages = count($pages);
$numPages = 7;//cause I don't have the real var for testing
$howMany = 1;
?>
<?php if ($numPages > 1): ?>
<li>Page <?php echo $currentPage?> of <?php echo $numPages?></li>
<?php if ($currentPage > 1): ?>
<li><a href="imgit_images.php?page=1">First</a></li>
<li><a href="imgit_images.php?page=<?php echo $currentPage-1?>"><</a></li>
<?php endif; ?>
<?php if ($currentPage > $howMany + 1): ?>
<li>...</li>
<?php endif; ?>
<?php for ($pageIndex = $currentPage - $howMany; $pageIndex <= $currentPage + $howMany; $pageIndex++): ?>
<?php if ($pageIndex >= 1 && $pageIndex <= $numPages): ?>
<li>
<?php if ($pageIndex == $currentPage): ?>
<u>
<?php endif; ?>
<a href="imgit_images.php?page=<?php echo $pageIndex?>"><?php echo $pageIndex?></a>
<?php if ($pageIndex == $currentPage): ?>
</u>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endfor; ?>
<?php if ($currentPage < $numPages - $howMany): ?>
<li>...</li>
<?php endif; ?>
<?php if ($currentPage < $numPages): ?>
<li><a href="imgit_images.php?page=<?php echo $currentPage+1?>">></a></li>
<li><a href="imgit_images.php?page=-1">Last</a></li>
<?php endif; ?>
<?php endif; ?>
这篇关于截断分页中的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:截断分页中的页数
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01