Exclude subpages of subpage in tree menu

How can you exclude in the tree menu the subpages of a certain page which is also a subpage?

The folder-structure is like this:

                          article3 etc.

All the different named articles should be excluded from the tree menu.

My problem is, that Ive already set one subpage only that should be shown:


// get the first set of subpages which should be used
$subpages = $pages->find('about-us')->children();

// create the snippet beginning with those subpages
snippet('treemenu', array('subpages' => $subpages));


So I want to show the ‘about-us’-subpages without the articles.

How can you do that?

When you say tree menu, I assume you are referring to Bastian’s tree menu? If that’s the case then perhaps this thread helps.

Thank you for the tip, but that’s not about the tree menu, so I would have to rebuild the navigation from the beginning.

In the line

$subpages = $pages->find('about-us')->children();

can you define further children of the subpage ‘news’, which are excluded from $subpages? So first

$subpages = $pages->find('about-us')->children()

and then in principle going on like that:

->find('news')->dont show children

Is that possible?

i don’t understand what you mean, the thread i linked to was indeed about the tree menu :slight_smile:

In that thread was a post describing how to filter out pages based on template (or some other feature unique to them). Something like this:

<?php foreach($subpages->visible()->filterBy('template', '!=', 'newsarticle') as $p): ?>

newsarticle is the name of your news template. See here for more, and the post below at that describes filtering on more then one template if you need to.

But why would you want to find the news page if you don’t want it’s children? Are there other children of about-us whose grandchildren you do want to fetch?

Maybe you can post your complete navigation to make it clearer what you want to do.

Sorry jimbobrjames, didn’t realise it was the tree menu. The filter helped a bit but i couldnt exclude the articles with

$subpages = $pages->find('about-us')->children()->filterBy('template', '!=', 'nachricht');

‘nachricht’ is the template of all the articles. When I set in ‘news’, which is the name of the page and the template, it worked but the news-page is of course also excluded from the menu.

I want to exclude all the subpages of ‘news’ from the main (tree) navigation as these pages contain just short messages that are implemented in blog-style. They can contain pictures sometimes, so a structure didn’t work here.
All grandchildren of ‘about-us’ can be excluded from the menu.

Here is the complete folder structure of the site:

about us
                article3 etc.

The problem I think is that you are being too specific with the $subpages variable. I think really you need every page in the site, except those using the nachright template. Your tree menu should look something like this:

<?php if(!isset($subpages)) $subpages = $site->pages()->visible() ?>
  <?php foreach($subpages->filterBy('template', '!=', 'nachricht') as $p): ?>
  <li class="depth-<?= $p->depth() ?>">
    <a<?= ($p->isActive()) ? ' class="active"' : '' ?> href="<?= $p->url() ?>"><?= $p->title() ?></a>
    <?php if($p->hasVisibleChildren()): ?>
      <?php snippet('treemenu', array('subpages' => $p->children())) ?>
    <?php endif ?>
  <?php endforeach ?>