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:
<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?

 
okhayat replied on at Permalink Reply
okhayat
Isn't a method like getNumChildren() or getNumChildrenDirect() useful in this case? Something like:
<?php
if ($c->getNumChildren()) echo 'class="parent-page"';?>
c5mix replied on at Permalink Reply
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?
if ($c->getNumChildren()) {
            $navDropdown='nav-dropdown';
         } else {
            $navDropdown = '';
         }
if(empty($navSelected) and empty($isFirstClass) and empty($navDropdown)){
                $liClass='';
            }else{
                 $liClass='class="'.$navSelected.' '.$isFirstClass.' '.$navDropdown.'"';
            }
         $output[]= '<li '.$liClass.'>';
ScottC replied on at Permalink Reply
ScottC
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.
}

?
c5mix replied on at Permalink Best Answer Reply
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 = '';
         }
hursey013 replied on at Permalink Reply
hursey013
very helpful - thanks.
platypusman replied on at Permalink Reply
platypusman
Please excuse my ignorance with PHP but where exactly are you putting this code?

Thanks.