Pagination issues


#1

Hello,

I’m trying to integrate the exact same pagination (bulma css framework):

I managed to make the previous, next buttons and range pagination work, i also made the first and last page button. Now in the middle there is the pagination range, and i can’t manage to find a solution:
When there is less than six pages, it should just display 1 2 3 4 5, when there is at least six pages it should display 1 … 2 3 4 … 6 , etc… While displaying current, previous and next page on the pagination range…

Edit: after thinking more about that it looks like its more difficult than that, because there shouldnt be the “…” if there is no page between the first fixed page button and the first page displayed by the pagination range… same for the last…

Also, very strangely, my page:2 lend on an error page but all the other pages works…


#2

Is there an error involved in one of the subpages of the second “paginated set” you’re paginating?
Is debugging turned on?


#3

debug mode is on, and there is no error involved with the subpage… i even deleted it for another subpage to take place… same issue…


#4

Is there more than one pagination on the page?


#5

Nope, here is my pagination snippet, and there isn’t any else pagination on the page :
https://pastebin.com/vv9Ba1C9


#6

I can’t see anything wrong with that snippet, do you use any plugins? What is your Kirby version?

Is the project online anywhere?


#7

So, i put it online for you to eventually review… And on my remote server blog’s pagination page:2 is working, now we know that it was a server issue, maybe triggered by some code issue tho… Here is the link to the installation, let me know if you need the zipped folder.

Edit, i’m running on MAMP locally on a mac book pro. Apache, php 7.1.12. I can paste you my whole php info if needed


#8

Hm, interesting, I’m running on Mamp on a MacBook Pro as well and never had issues with the pagination, no matter what PHP version. If you want, you could provide a zip. and. I could throw it into my. dev environment to see if I run into. the same issue.


#9

Here you are:
http://www.studioperrier.fr/kirby_start/kirby_start.zip


#10

Thanks, can’t reproduce the issue in my installation, tried with both PHP 7.1.12 and 7.2.1.


#11

Im going to go with it for the moment, will reinstall mamp clean and try…

Thanks for your help. What about my first issue? If you see the blog pagination you’ll understand what ly problem is, trying to hide first and last page from pagination range as they are already showed out of the range, and try to hide the “…” when there is no hidden page before the first pagination range or after the last… hard t o explain, and english isnt my native language…


#12

Yes, I understand the problem, but have to think how to best handle that without a lot of if statements or hiding stuff via CSS.


#13

Ok, hope you find a way, could be nice for a cookbook.


#14

What do you want to happen if the range includes either the last page or. the first page? For example, if your range is set to 2, the pagination range shows 3 pages. If you hide/remove the first or the last, you would end up with less pages in the range. Is that the desired behavior?

In your example, the active page is in the center of the range. But this won’t work for the first two and the last two pagination pages.


#15

Hi, i think it would be best described by a “use case”, it need to behave differently when the user is on the 3 last or 3 first pagination pages (active page is bold):

1 2 3 4 … 15
1 2 3 4 … 15
1 2 3 4 … 15
1 … 3 4 5 … 15
1 … 4 5 6 … 15
1 … 9 10 11… 15
1 … 11 12 13 … 15
1 … 12 13 14 15


#16

I think this will work:

<?php foreach($pagination->range(2) as $r): ?>

  <?php
  $noOfPages = $pagination->countItems();
  if($pagination->page() <= 2) {. $r = $r+1 ; }
  if(in_array($pagination->page(), [$noOfPages,$noOfPages-1])) {$r = $r-1;}

  ?>

    <li><a class="pagination-link<?php if($pagination->page() == $r) echo ' is-current' ?>" href="<?= $pagination->pageURL($r) ?>" aria-label="<?php if($pagination->page() != $r) echo 'Goto ' ?>Page <?= $r ?>"
      <?php if($pagination->page() == $r) echo 'aria-current="page"' ?>><?= $r ?></a></li>
 <?php endforeach ?>

Then all that should be left is to apply some. similar. logic to display the ellipsis or not.

First ellipsis:

<?php if($pagination->page() > 3): ?>
    <li><span class="pagination-ellipsis">&hellip;</span></li>
<?php endif ?>

Second:

<?php if($pagination->page() < $noOfPages - 2 ): ?>
    <li><span class="pagination-ellipsis">&hellip;</span></li>
<?php endif ?>

#17

Great! im going to try it when im home and keep you updated!


#18

It’s working ! Thanks!