I am having a php recursive function to display my categories with sub, sub-sub category.
Its look like below:
function displayList(&$cats, $parent, $current=0, $level=0) {
if ($parent==0) {
foreach ($cats[$parent] as $id=>$nm) {
displayList($cats, $id, $current);
}
}
else {
echo "<ul>
";
foreach ($cats[$parent] as $id=>$nm) {
$sel = $current==$id ? ' active' : '';
//$indent = str_repeat('– ', $level);
echo "<li><a href='' class='$sel'>$nm</a>
";
if (isset($cats[$id])) {
displayList($cats, $id, $current, $level+1); //increment level
}
echo '</li>';
}
echo "</ul>
";
}
}
Here I want to add a CSS
class for each parent <li>
, if it has a sub, sub-sub categories.
My HTML is something like this:
<ul>
<li><a href="product_category.html">Party Balloons</a></li>
<li><a href="">Party Tableware</a></li>
<li class="parent"><a href="">Party Decorations</a>
<ul>
<li><a href="">Lorem ipsum dolor sit amet </a></li>
<li class="parent"><a href="">Conse ctetur adipisicing </a>
<ul>
<li><a href="">Dolore magna aliqua</a></li>
<li><a href="">Ut labore et </a></li>
</ul>
</li>
<li><a href="">Elit sed do eiusmod tempor</a></li>
<li><a href="">Incididunt ut labor</a></li>
</ul>
</li>
<li><a href="">Party Banners</a></li>
</ul>
Can anybody tell me how can I do it? Thanks in advance.