Jump to content

Sub-navigation to another level?


antknight
 Share

Recommended Posts

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

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...