Pagination in per month archive

Hi,

I would like to create an archive page, collecting all blog-posts in a per month view. However, already the number of month is quite high, so I would like to paginate.
The code here paginates by number of articles, however, I don’t know the number in each month.

Currently I use this code for collecting all entries in a given month:

<?php $articles = page('thepage')->children()->filterBy('date', '<=', $end_date) ->filterBy('date','>=', $start_date)->visible() ?>
<?php foreach($articles as $article): ?>

Any suggestions?

Hey there!
In order to paginate through your months, you need to transform your list of months into a collection, and then use pagination in that collection.

See for more info:
https://getkirby.com/docs/toolkit/api/collection/paginate

Thanks!
How would I initiate a new collection? just

$month_collection = new $collection();

?
As I understand afterwards I could fill the collection just with append.

Daniel

I believe there is no $ before collection

$month_collection = new Collection();

A good example here:

PS: it seems like new Collection always takes a capital C in the examples I found. Don’t know if it is indeed mandatory.

It is a convention to write class names with a capital letter, so instances of a class should also be written with a capital letter.

1 Like

If you want to have each month on its own page, you can groupBy the month and then paginate with 1 item (month) per page.

Hey Daniel, did the solution work for you?

Hi,

I did follow your suggestion and it worked!!
However, now I switched to my own pagination using the URI params. I wanted to have the pages according to the years, however since not all month are filled I cannot just use “pagination(12)”.

Daniel

Can we mark this as solved?

1 Like

Yes (foo bar, since I cannot just answer yes)

1 Like