antknight Posted February 24, 2013 Share Posted February 24, 2013 This should be an easy one! Currently in the default theme for sub-navigation is the following code: if($page->path != '/' && $page->rootParent->numChildren > 0) { echo "<ul id='subnav' class='nav'>"; foreach($page->rootParent->children as $child) { $class = $page === $child ? " class='on'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } echo "</ul>"; } Which works great for a structure like: Home -Cricket Club --News --About --Contact Class of 'on' is added to each of the news, about and contact pages when you are viewing them, but I want to go one more level. For example when viewing a child page of news, News link should still have class of 'on' applied. Even after studying this post I couldn't figure it out! How can I achieve this? Link to comment Share on other sites More sharing options...
Wanze Posted February 24, 2013 Share Posted February 24, 2013 With a little addition: $class = ($page === $child || $page->parents->has($child)) ? " class='on'" : ''; $page->parents returns a WireArray with all the parents and ->has checks if the current Nav-Item is in there. 1 Link to comment Share on other sites More sharing options...
antknight Posted February 24, 2013 Author Share Posted February 24, 2013 This is very clever, I would never have been able to figure it out. Many Thanks Wanze! 1 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