How to get a collection with all pages from last depth(s)?

Hello :smile:

I have the following folder structure:

    - apples
       - red apple
       - green apple
       - yellow apple
    - bananas
    - pineapples
    - grapefruit
       - red grape
       - white grape
       - rose grape
    - carrots
    - potatoes
    - beets
    - tomatoes

What I need to get is only the last child folder of each particular instance, to get, as an example:

red apple, green apple, yellow apple, bananas, pineapples, red grape, white grape, rose grape, carrots, potatoes, beets, tomatoes

I’ve tried nesting foreach cycles and I’ve made it work for three levels, but sometimes the structure grows deeper.

Thanks in advance!

Edit: I just realized tomatoes are, ‘technically’, fruits. Haha.

These pages don’t happen to share something they have in common by which you can filter, like the same template, a field, or something like that?

Hmm… I had not thought about the template. Yes, it seems they all share the same template. I think I have an idea.

Then you can filter by template() or intendedTemplate():

$collection = page('food')->index()->filterBy('template', 'abc');
1 Like