getPaginationLinks()
Get pagination links based on the current page
Usage
site()->getPaginationLinks();
Returns
Type | Description |
---|---|
array | - |
↳ "older" | string|false – URL to the previous posts page, or false if there aren’t any older posts. |
↳ "newer" | string|false – URL to the next posts page, or false if there aren’t any newer posts. |
↳ "totalPages" | int – Total amount of pages |
↳ "currentPage" | int – Index of the current page, starting at 1 |
Example
site()->getPaginationLinks();
// Results
[
"older" => "http://my.epic.site/blog/page/3/",
"newer" => "http://my.epic.site/blog/",
"totalPages" => 3,
"currentPage" => 2
]
Passing pagination links into a template is very easy:
echo site()->view("blog-archive", [
"pagination" => site()->getPaginationLinks(),
]);
<!-- tpl/blog-archive.tpl -->
...
{{#if pagination.older }}
<a href="{{ pagination.older }}">Older Posts</a>
{{/if}}
{{#if pagination.newer }}
<a href="{{ pagination.newer }}">Newer Posts</a>
{{/if}}