Hi, as suggested in many posts also here on this forum, I always organized pages and sub-pages using a year/month structure like this one:
Most of the queries though are about displaying articles sorted by date.
I always use a syntax like:
And, if I need to get the articles of a certain year, I just use a query like
return $child->date()->toDate(‘Y’) === $year;
Question is: is this the correct approach, or (having performances in mind) should I consider the year based folder - assuming all the articles of that year are stored in the correct folder (which unfortunately is not always the case)? Something like
$pages->find(‘articles/’ . $year)->grandChildren()
If you know the year, you only have to get the year folder, so
$site->find('articles/2018')->grandChildren() would be the best approach, instead of filtering the whole lot. Much shorter and you don’t have to read the content files.
On a side note, you can define your articles collection one as Kirby collection and then reuse across your site (without having to redefine if you need the collection in multiple places):
Thanks for the answer.
What index() exactly does? I’ve read on Kirby reference that “it create a flat child index”, but in practice…? And why using the template method?
I need to understand…
I never used Collections. I tried to solve the same problem (reuse the most used queries through the site) with a plugin. So I can pass to the function some arguments if I need to filter the query.
Do collection makes more sense?
(Sorry to bother you, I’m a heavy user of Kirby kb but…)
index() gives you a flat list of all pages under a given page. The reason why I added the filter by template is because otherwise the list would include the parent pages (year and month folders)
Not necessarily, e.g. you cannot pass parameters to a collection.
Interesting. How would this work if one’s blog structure as far as the file system is concerned is something like
Not sure what exactly you mean. To get what result?
Sorry, I thought that would be contextual. To call simple reverse-chron lists of blogs posts; I guess to start with on the homepage whuch will at least get my head pointed in the right direction.