Collection archive pages have a $pagination
object injected into them:
<ul>
@foreach ($pagination->items as $post)
<li><a href="/{{ $post->path }}">{{ $post->title }}</a></li>
@endforeach
</ul>
@if ($pagination && $pagination->lastPage > 1)
<div class="pagination">
@if ($pagination->prevPagePath)
<a href="/{{ $pagination->prevPagePath }}"><</a>
@endif
@for ($i = 1; $i <= $pagination->lastPage; $i++)
<a href="/{{ $pagination->path }}/page/{{ $i }}">{{ $i }}</a>
@endfor
@if ($pagination->nextPagePath)
<a href="/{{ $pagination->nextPagePath }}">></a>
@endif
</div>
@endif
The $pagination
object has the following attributes:
items
- An array of entries for this pagecurrentPage
- The index of the current pageperPage
- The number of entries per pagelastPage
- The index of the last pagetotal
- The total number of entriespath
- The base path for the collection (e.g. posts
)firstPagePath
- The path for the first page (e.g. posts/page/1
)lastPagePath
- The path for the last page (e.g. posts/page/9
)nextPagePath
- The path for the next page (e.g. posts/page/2
)prevPagePath
- The path for the previous page (e.g. posts/page/8
)