Branch menu as submenu with excluded sub(-sub)pages, displayed on one level

Hm, I did a quick test:

Let’s suppose I have the following templates/snippets:

artist.php for the single artist
blog.php for a blog subpage of single artist
top-menu.php snippet for the top menu

top-menu.php snippet:

<nav>
  <a <?php ecco($page->isOpen() && ! $page->hasParent(), ' class="active"') ?> href="<?= $page->url() ?>"><?= $page->title() ?></a>
  <?php if($page->hasChildren()): ?>
    <ul class="submenu">
      <?php foreach($page->children() as $item): ?>
        <li><a<?php ecco($item->isOpen(), ' class="active"') ?> href="<?php echo $item->url() ?>"><?php echo html($item->title()) ?></a></li>
     <?php endforeach ?>
   </ul>
 <?php endif ?>
</nav>

artist.php template:

<?php snippet('header') ?>
<?php snippet('top-menu') ?>
  <main class="main" role="main">
  </main>
<?php snippet('footer') ?>

blog.php template:

<?php snippet('header') ?>
<?php snippet('top-menu', array('page' => $page->parent())) ?>
  <main class="main" role="main">
  </main>
<?php snippet('footer') ?>

For me, this works perfectly.

Great! I can now work with it. There is only a thing that I wonder whether it is possible to solve with code only:

Right now I have three templates for the artist to chose between: simple, blog, projects. If you look at the setup in my fist post you can see, that an artist can chose one of these three templates to start with. Maybe he/she wants to write a blog but also to have a simple page for acknowledgements. Then the blog is the parent of the simple page. But maybe he wants to start with a simple page, describing his piece of work in general, but in addition a blog as a project diary. Then the simple page ist the parent of the blog: it’s just the other way around!

I will work with that now. I think I will just allow to use a simple page to be the starting page and the blog and projects as child pages. That is enough for my purpose.

A big thank you, Sonja!

IMHO, the most logical way to structure your content would be to have blog, simple page and projects as subpages on the same level, i.e. as subpages to the individual artist, and not simple page as subpage of blog or vice versa. Then a simple page would not allow child pages, whereas projects and blog would allow one level of subpages, i.e. sth. like article.php for a blog subpage, and project.php for a projects subpage.

- artists
  - artist-1
    - blog
      - article-1
    - projects
      - project-1
  - artist-2
    - simple page
    - blog
      - article-1
  - artist-3
    - projects
      - project-1
      - project-2
    - simple page

The advantage of doing it that way is that your artists can choose what to use as their landing page still. You can in your artist template use the following:

// Selects the first sub-page of the artist page as the landing page
<?php go($page->children()->visible()->first()); ?>

It seems that the artist page is a page in itself, e.g. about the exhibit, so it would not be such a good idea to redirect to one of the children.

I assumed that the simple page would be used for that purpose. I may have gone sideways here :slight_smile:

Yes, it is that way, and that page will most probably contain a list with short biographies. I did exactly as you did, texnixe - it works fine!

Glad that we finally found a solution. It’s sometimes difficult to get at it if the structure is a bit less straighforward, and without an example or the exact structure. So the link to the site really helped a lot.

You helped a lot. And thanks to Thiousi for bumping up the topic.The link will be deleted now…

1 Like

Good luck with your website now ! And you know where to find us if you need to!
I only bumped it but I meant to help you fix it too, @texnixe didn’t give me enough time (she is soooo fast :stuck_out_tongue:)!

I’m so sorry, @Thiousi :smirk: I’m still female, though … can’t fix this that fast.

:scream:I’m sooooorrrryyyyyyyyyyyyyyyyyyy !!!
I’ve corrected it above (as if it were just a typo in a code line you know…)

I don’t believe I knew you were ! It doesn’t really make a difference now that I know except that I think I may have called you “he” half a dozen times. Oh well…