joe_ma Posted August 25, 2018 Share Posted August 25, 2018 Hi Trying to setup a customized navigation. Page tree looks like this: home – upcoming exhibitions –– exhibition 1 –– exhibition 2 –– … – about – archive –– arch 1 –– arch 2 –– … – impressum Now I'd like to have a navigation, that lists only the subnav of "upcoming exhibitions" but not the one of "archive". I modified a snippet I found here in the forum. It looks like this so far: <nav class="mainNav"> <ul> <?php $homepage = $pages->get('/'); // first item links to the homepage echo "<li><a href='$homepage->url'>Aktuelle Ausstellung / current exhibition</a></li>"; $children = $homepage->children(); // render an <li> for each top navigation item foreach ( $children as $child ) { if ( $child->id == $page->rootParent->id ) { // this $child page is currently being viewed (or one of it's children/descendents) // so we highlight it as the current page in the navigation echo "<li class='active'><a href='$child->url'>$child->title</a></li>"; // if upcoming page has children, list them } elseif($child->id == 1020 && count($child->children)){ // build the subnav and list all items echo "<li><a href='$child->url'>$child->title</a><ul class='upcoming'>"; foreach($child->children as $c){ echo "<li><a href='$c->url'>$c->title<br>{$c->date_from}–{$c->date_to}</a></li>"; } echo "</ul><li>"; // otherwise list only main items } else { echo "<li><a href='$child->url'>$child->title</a></li>"; } } ?> </ul> </nav> This puts out the navigation as wanted, but only for main items (see fig. nav-open.png). As soon as "upcoming exhibitions" or one of its children is active, the navigation collapses (see fig. nav-closed.png). I cannot find out, where I went the wrong way. Thanks for help. Link to comment Share on other sites More sharing options...
dragan Posted August 25, 2018 Share Posted August 25, 2018 Where do you want to place this navigation? In root, or only in the exhibition pages? Link to comment Share on other sites More sharing options...
joe_ma Posted August 25, 2018 Author Share Posted August 25, 2018 Everywhere. Link to comment Share on other sites More sharing options...
dragan Posted August 25, 2018 Share Posted August 25, 2018 $home = $pages->get('/'); foreach($home->children as $child) { $content .= "<a href='{$child->url}'>{$child->title}</a><br>"; if($child->id !== 1035) { if($child->hasChildren) { foreach($child->children as $child2) { $content .= "- <a href='{$child2->url}'>{$child2->title}</a><br>"; } } } } page id 1035 would be archive parent 3 Link to comment Share on other sites More sharing options...
joe_ma Posted August 25, 2018 Author Share Posted August 25, 2018 Thanks a lot. Works like a charm and is – of course – much more elegant than my gobbledigook. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now