What I did before was a tree display, but actually I try to get just the branch.
This Kirby blog article helped to solve at least the second level part: https://getkirby.com/blog/fun-with-menus
What I could do is to call two loops: one for the first level (in this case “artist …” – in the Kirby hierarchy a sublevel) and one for the second level (in the Kirby hierarchy a sub-sublevel).
The loop (for “artist …”) taken from the blog example is this:
<?php
$items = false;
// get the open item on the first level
if($root = $pages->findOpen()) {
// get visible children for the root item
$items = $root->children()->visible();
}
// only show the menu if items are available
if($items && $items->count() > 0):
?>
<nav>
<ul>
<?php foreach($items 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>
</nav>
<?php endif ?>
What I obtain is that all the artists are listed. But I only want to see the current artist, both on the artist level and the second level. Is there any way to solve this?
I love trying to fix this kind of situations, and I find that most of the time, the challenge is actually in the plain text part and not in the code part
Reading through the post. I think I missed at some point the actual goal you are trying to achieve. Has your goal changed since your first post?
If so, would you be able to lay it out again?
Haha, thank you very much! I usually don’t like to do that: to post a link to non-working websites, hm. But here you go because a living example is always better than too many confusing words. So please take it as a work in progress; I will delete the link again after a while:
So you got your sidebar menu and a top menu. Now, if I understand correctly what you explained above, the top menu should only show the artist you selected in the sidebar menu together with the artist’s subpages all in one line?
Yes, exactly! And I would love the current page to be marked as active (for instance now when you click on “Einfache Seite” or “Projekte” the link is underlined. But not “Künstler 1”).
I tried this with several combinations, but it did not work. Also I need to call a template sooner than a page.
Anyhow: it seems more tricky than it looks, especially for me as a PHP beginner. I am very grateful for your help! But if this takes too much time to solve, please leave it the way. Visually I can solve this (in a very hacky way, I know) with CSS.
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.