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; ?>
这篇关于截断分页中的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:截断分页中的页数
				
        
 
            
        基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - php中的PDF导出 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				