Roman
January 7, 2024, 9:30pm
1
We have a lot of pages, so pagination looks like this:
How can I make it more compact? Maybe there is an option to group them or skip middle part? Or to show first ten, and then next as 20, 30, 40…?
(Showing more items on one page can’t be a solution here, as there are already quite enough of items on one page).
You can control that via the parameter you pass to $pagination->range()
, e.g. $pagination->range(5)
, then add dots before and after conditionally.
See also the Pagination class methods: $pagination | Kirby CMS
Roman
January 7, 2024, 10:25pm
3
Thanks, I am only confused how it works:
I had this code before:
<?php $itemsonpage = $page->itemsonpage()->toInt() ?>
<?php foreach ($pagination->range("$itemsonpage") as $r): ?>
it was limiting to required number of items on one page, but showing all pages.
After I changed it to:
<?php $itemsonpage = $page->itemsonpage()->toInt() ?>
<?php foreach ($pagination->range(10) as $r): ?>
it’s also limiting number of items on page, but now showing 10 pages at one time.
If I undersand correctly, $itemsonpage should define how many articles are shown per page, so this variable should be passed to $pages->paginate()`, which defines the number of items per page.
range()
however refers to the ranger of pagination pages to be shown.