分页显示页数过多

Posted 万里冰封

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分页显示页数过多相关的知识,希望对你有一定的参考价值。

原文:http://blog.csdn.net/u011897510/article/details/77823390

核心代码:

@if ($paginator->hasPages())
    @php
    //指定显示的页码数量,取值范围3-n
    $paging_number = 6;
    if($paging_number<3){
    $paging_number = 3;
    }
    //当前页
    $paging_current_page = $paginator->currentPage();
    //共几页
    $paging_last_page = $paginator->lastPage();
    if(($paging_number%2) == 0){
    if($paging_last_page <= $paging_number){
    $paging_start = 1;
    $paging_end = $paging_last_page;
    }else if($paging_current_page < ($paging_number/2+1)){
    $paging_start = 1;
    $paging_end = $paging_number;
    }else if($paging_current_page >= ($paging_number/2+1) && (($paging_current_page + ($paging_number/2 - 1)) <= $paging_last_page)){
    $paging_start = $paging_current_page - ($paging_number/2);
    $paging_end = $paging_current_page + ($paging_number/2 - 1);
    }else{
    $paging_start = $paging_last_page - $paging_number + 1;
    $paging_end = $paging_last_page;
    }
    }else{
    if($paging_last_page <= $paging_number){
    $paging_start = 1;
    $paging_end = $paging_last_page;
    }else if($paging_current_page < ceil($paging_number/2)){
    $paging_start = 1;
    $paging_end = $paging_number;
    }else if($paging_current_page >= ceil($paging_number/2) && (($paging_current_page + floor($paging_number/2)) <= $paging_last_page)){
    $paging_start = $paging_current_page - floor($paging_number/2);
    $paging_end = $paging_current_page + floor($paging_number/2);
    }else{
    $paging_start = $paging_last_page - ($paging_number - 1);
    $paging_end = $paging_last_page;
    }
    }
    @endphp
    <ul class="pagination">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="disabled"><span>?</span></li>
        @else
            <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">?</a></li>
        @endif

        {{-- Pagination Elements --}}
        @for ($i = $paging_start; $i <= $paging_end; $i++)
            @if ($i == $paginator->currentPage())
                <li class="active" ><span >{{ $i }}</span></li>
            @else
                <li><a href="{{ $paginator->url($i) }}">{{ $i }}</a></li>
            @endif
        @endfor

        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">?</a></li>
        @else
            <li class="disabled"><span>?</span></li>
        @endif
    </ul>
@endif

 

以上是关于分页显示页数过多的主要内容,如果未能解决你的问题,请参考以下文章

SQL 分页代码

SQL 分页代码

Django中使用JS通过DataTable实现表格前端分页,每页显示页数,搜索等功能

求php数字分页算法

限制bootstrap 3分页中显示的页数

Codeigniter 分页显示结果数和页数