If a Page has Sub Pages add class
Permalink 2 users found helpful
I am trying to figure out how to add a class to a <li> in the autonav header menu if that page has sub pages. So, if the page has sub pages I'd want the output to be something like this:
If the page doesnt have sub pages, then no class="parent-page" is added.
Anyone know how to do this?
<li class="parent-page"><a href="#">Page Title</a></li>
If the page doesnt have sub pages, then no class="parent-page" is added.
Anyone know how to do this?
Isn't a method like getNumChildren() or getNumChildrenDirect() useful in this case? Something like:
Here's what I got, but it's not working. It puts a class of nav-dropdown on every li (even ones that dont have children). Any ideas how to fix?
i dunno, there's like 5 ways to do anything.
I'd go about it by doing if(!empty($c->getCollectionChildrenArray()){
//i have kids
}else{
//i have dogs.
}
?
I'd go about it by doing if(!empty($c->getCollectionChildrenArray()){
//i have kids
}else{
//i have dogs.
}
?
Here's the code I ended up with and it works. Basically, it sees if the page has sub pages and if it is top level. If those are true it adds a certain class (except if that page is the home page).
if ($_c->getNumChildren() > 0 && $thisLevel < 1) { $navDropdown = 'nav-dropdown'; } else { $navDropdown = ''; } if ($isFirst) { $navDropdown = ''; }
very helpful - thanks.
Please excuse my ignorance with PHP but where exactly are you putting this code?
Thanks.
Thanks.