# Subpages in Subpages with foreach loop

**URL:** <https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956>\
**Category:** Questions\
**Tags:** v2\
**Created:** [April 25, 2016, 9:18pm UTC](https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956 "2016-04-25T21:18:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwd0tcom](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dwd0tcom/32/6131_2.png) [@dwd0tcom](https://forum.getkirby.com/u/dwd0tcom)\
**Post date:** [April 25, 2016, 9:18pm UTC](https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956/1 "2016-04-25T21:18:05Z")

</div>

Hello everybody,

I’m working on a project for a restaurant. The owner wants to edit his menu via kirby. So I created a css file which makes the HTML look like the menu he gives out in his restaurant.  
I created a page which has the subpages for the categories like soup or salat, in this subpages are again subpages with the meals and the prices. So far so good, now on to the problem:

I created a foreach loop to show all categories and in this loop another loop to show the meals. But here must be my mistake, every category has all meals in it. Do you guys no how to handle this problem? I’m completely stuck here.

Thanks in advance!

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/6/69556ada3274923d69e5c8840d7c6d1d07c52d7a.png)

---

<div class="post-metadata">

**Author:** ![dwd0tcom](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dwd0tcom/32/6131_2.png) [@dwd0tcom](https://forum.getkirby.com/u/dwd0tcom)\
**Post date:** [April 25, 2016, 9:21pm UTC](https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956/2 "2016-04-25T21:21:18Z")

</div>

Ok, after thinking again what I did, I came up with this solution.  
I would like to show it to you, maybe somebody else has the same problem:

 ![](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/4/4edf28c2ad419df53aab49fc399396a563040e20.png)

---

<div class="post-metadata">

**Author:** ![LCD344](https://avatars.discourse-cdn.com/v4/letter/l/90ced4/32.png) [@LCD344](https://forum.getkirby.com/u/LCD344)\
**Post date:** [April 25, 2016, 9:21pm UTC](https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956/3 "2016-04-25T21:21:31Z")

</div>

It looks like you are looping on all the grandchildren when you print every categorie,

you need to change the inner foreach to only happen on the categorie something like (untested)

`$kategorie->children() as $speise`

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:59pm UTC](https://forum.getkirby.com/t/subpages-in-subpages-with-foreach-loop/3956/4 "2025-02-06T16:59:43Z")

</div>

Archived on February 6, 2025, 4:59pm UTC


