Hello, I’d like to inquire.
I’m using “pagination”.
In the order of recent posts, you can see 10 posts on a page. Post numbers start with number 1. By the way, can I change the post number upside down?
For example, if there are 40 posts in total and I write the 41st new post, the number of the new post will be 41, not 1. Keep the order from the top of page 1, and just the page numbers are 41, 40, 39… Can I change it like this?
link
https://dy.co.kr/kr/dy/electronic-notice
<?php $list = $page->children()->index()->filterBy('template', 'article') ?>
<ul id="listPage">
<?php foreach ($list->paginate(10) as $item) : ?>
<li>
<span class="number"><?= $list->indexOf($item) + 1 ?></span>
<span class="listdate"><?= $item->urldate() ?></span>
<span class="listsubject"><a href="<?= $item->url() ?>"><?= $item->urltexts() ?></a></span>
</li>
<?php endforeach ?>
</ul>
Hm, you are calling the complete pages index (so all children all the complete subpages of children tree) here, is that by mistake? Ordering them by number in this case will likely not work as expected.
https://forum.getkirby.com/t/id-like-to-make-a-page-number-for-the-pagenation/22500/5
This is a problem that was solved through this process with the help of the forum!
But my client asked me to fix it…
You can invert the order using flip()
, for example:
$list = $page->children()->listed()->flip();
But as already mentioned, when you call $page->children()->index()
, you will get a list of the complete page tree under the given page, so the children, and their children etc. Is that what you want?
There is no problem with that part yet. It’s okay.
But my question is…
Now, (for example, if there are 40 posts in total), the most recent post number is “1”, but I want to change it to 40.
https://dy.co.kr/kr/dy/electronic-notice
40 The most recent post.
39 The next post.
38
37
…
1 The oldest post.
You can substract the current index from the number of items:
<?php
$list = $page->children()->index()->filterBy('template', 'article');
$itemCount = $list->count();
?>
<ul id="listPage">
<?php foreach ($list->paginate(10) as $item) : ?>
<li>
<span class="number"><?= $itemCount - $list->indexOf($item) ?></span>`
<span class="listdate"><?= $item->urldate() ?></span>
<span class="listsubject"><a href="<?= $item->url() ?>"><?= $item->urltexts() ?></a></span>
</li>
<?php endforeach ?>
</ul>
1 Like
Thank you for always helping me!