I’ve been building something along the lines of a blog - basically news articles which are added as seperate entries. This builds a lot of subpages of course, which I only got to sort properly by setting them as visible.
However, they now show up in the menu as subpages, which I don’t want. Is there any way to hide all the subpages of the “news” page from the menu?
I’m building a similar menu now. I’m not a proper developer so it will make real devs’ eyes bleed, but here’s how I did it so far.
I put the whole submenu in a different condition.
Instead of
As a fellow non-proper dev, I can say I’ve done the same thing multiple times. Works for me, but I’d be interested in seeing a “properly clean” way to solve this problem.
Instead of hardcoding pages in the template, you could also use a checkbox field in the parent pages (“Include subpages in menu?”) and then check if that field is true. That would make it more flexible in case there are other pages whose children are not supposed to appear in the menu (e.g. if the site is extended in the future).
Sorry for bringing this up again but I just wondered if someone can give a working example for excluding the children of a specific page. I tried all the suggestions above but didn’t manage to replicate a proper solution. I thought there might be a rather straight-forward way by adapting the example for a nested menu in the docs. I guess in this line (somehow) the magic could happen…
// get all children for the current menu item
$children = $item->children()->visible();
I tried to exclude the children of the Blog page by adding ->not('blog')->children() but didn’t succeed.