Laravel 自定义分页、数目调整、页码显示调整,减少Laravel默认分页器模板中的链接数,Laravel分页默认情况下,当您有大量页面时,Laravel将在页面之间插入三个点(...)。这比打印每个页面的链接要好得多,但是显示的链接数量仍然很高,通常仍会导致在移动设备上出现换行现象,下面的代码将在当前页面的两侧显示不超过2页,并且将显示三个点以及相应的首页和末页链接。我hidden-xs对三个点和首页/后页链接应用了一个class,以确保分页链接尽可能多地显示在移动设备上。
<?php @if ($paginator->hasPages()) <ul class="pagination pagination"> {{-- Previous Page Link --}} @if ($paginator->onFirstPage()) <li class="disabled"><span>«</span></li> @else <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li> @endif @if($paginator->currentPage() > 3) <li class="hidden-xs"><a href="{{ $paginator->url(1) }}">1</a></li> @endif @if($paginator->currentPage() > 4) <li class="disabled hidden-xs"><span>...</span></li> @endif @foreach(range(1, $paginator->lastPage()) as $i) @if($i >= $paginator->currentPage() - 2 && $i <= $paginator->currentPage() + 2) @if ($i == $paginator->currentPage()) <li class="active"><span>{{ $i }}</span></li> @else <li><a href="{{ $paginator->url($i) }}">{{ $i }}</a></li> @endif @endif @endforeach @if($paginator->currentPage() < $paginator->lastPage() - 3) <li class="disabled hidden-xs"><span>...</span></li> @endif @if($paginator->currentPage() < $paginator->lastPage() - 2) <li class="hidden-xs"><a href="{{ $paginator->url($paginator->lastPage()) }}">{{ $paginator->lastPage() }}</a></li> @endif {{-- 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 ?>
文章评论(0)