截断分页页数 [英] Truncate number of pages in pagination

查看:87
本文介绍了截断分页页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个很愚蠢的问题,但是我想不出任何可以帮助我进一步发展的东西.我希望缩短页面导航中的NUMBERS个.

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.

而不是像这样: 1、2、3、4、5、6、7、8

我希望它是: 1、2 ... 7、8

当我转到 2 时,现在应该在数字组中看到数字 3 .

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?>">&lt;</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?>">&gt;</a></li>
        <li><a href="imgit_images.php?page=-1">Last</a></li>
    <?php endif; ?>
<?php endif; ?>

这篇关于截断分页页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆