# About performances, and folder structure

**URL:** <https://forum.getkirby.com/t/about-performances-and-folder-structure/23461>\
**Category:** Questions\
**Created:** [September 18, 2021, 9:55am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461 "2021-09-18T09:55:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hvsrmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hvsrmusic/32/2722_2.png) [@hvsrmusic](https://forum.getkirby.com/u/hvsrmusic)\
**Post date:** [September 18, 2021, 9:55am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/1 "2021-09-18T09:55:34Z")

</div>

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:

articles  
|–2018  
|----01  
|----02  
|----…  
|–2019  
|----01  
|----02  
|----…

Most of the queries though are about displaying articles sorted by date.  
I always use a syntax like:

> $pages-\>find(‘articles’)-\>grandChildren()-\>children()-\>sortBy(‘date’,‘asc’)

And, if I need to get the articles of a certain year, I just use a query like

> $pages-\>find(‘articles’)-\>grandChildren()-\>children()-\>filter(function($child) use($year){  
> 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()

?

thanks

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 18, 2021, 10:19am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/2 "2021-09-18T10:19:04Z")

</div>

> [@hvsrmusic](#):
>
> $pages-\>find(‘articles’)-\>grandChildren()-\>children()-\>filter(function($child) use($year){  
> return $child-\>date()-\>toDate(‘Y’) === $year;  
> });

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.

> [@hvsrmusic](#):
>
> $pages-\>find(‘articles’)-\>grandChildren()-\>children()-\>sortBy(‘date’,‘asc’)

I’d use:

```auto
page('articles')->index()->template('article')->sortBy('date', 'asc');

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 18, 2021, 10:47am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/3 "2021-09-18T10:47:08Z")

</div>

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):

> **[Collections](https://getkirby.com/docs/guide/templates/collections)**
>
> It often happens that we need the same set of pages or files in multiple places across our site. Think of blog articles on the blog and on the home page for example. Collections help with not …

---

<div class="post-metadata">

**Author:** ![hvsrmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hvsrmusic/32/2722_2.png) [@hvsrmusic](https://forum.getkirby.com/u/hvsrmusic)\
**Post date:** [September 18, 2021, 10:52am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/4 "2021-09-18T10:52:16Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![hvsrmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hvsrmusic/32/2722_2.png) [@hvsrmusic](https://forum.getkirby.com/u/hvsrmusic)\
**Post date:** [September 18, 2021, 10:56am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/5 "2021-09-18T10:56:55Z")

</div>

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…)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 18, 2021, 10:57am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/6 "2021-09-18T10:57:03Z")

</div>

> [@hvsrmusic](#):
>
> What index() exactly does?

Excactly, `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)

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 18, 2021, 10:58am UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/7 "2021-09-18T10:58:27Z")

</div>

> [@hvsrmusic](#):
>
> Do collection makes more sense?

Not necessarily, e.g. you cannot pass parameters to a collection.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 6, 2023, 10:58pm UTC](https://forum.getkirby.com/t/about-performances-and-folder-structure/23461/9 "2023-12-06T22:58:14Z")

</div>

Not sure what exactly you mean. To get what result?
