I have the following structure of categories in my Opencart
<ul>
<li class="bu">
<a href="http://brandoutlet.lv/index.php?route=product/category&path=205" class="active">PARENT 1</a>
<ul>
<li>
<a href="/index.php?route=product/category&path=205_66"> CHILD 1</a>
<ul>
<li><a href="index.php?route=product/category&path=205_66_230"> - GRANDCHILD 1</a></li>
<li><a href="/index.php?route=product/category&path=205_66_229"> - GRANDCHILD 2</a></li>
<li><a href="/index.php?route=product/category&path=205_66_228"> - GRANDCHILD 3</a></li>
</ul>
</li>
<li>
<a href="/index.php?route=product/category&path=205_67" class="active"> CHILD 2</a>
<ul>
<li><a href="/index.php?route=product/category&path=205_67_231"> - GRANDCHILD 1</a></li>
<li><a href="/index.php?route=product/category&path=205_67_217"> - GRANDCHILD 2</a></li>
<li><a href="/index.php?route=product/category&path=205_67_216"> - GRANDCHILD 3</a></li>
<li><a href="/index.php?route=product/category&path=205_67_215"> - GRANDCHILD 4</a></li>
</ul>
</li>
</ul>
</li>
<li class="bu">
<a href="/index.php?route=product/category&path=206"> PARENT 2</a>
//....ETC
How can I give Parent, Child and Grandchild different styling (color, weight, decoration)?
I was trying to make it work with JS searching for UL and applying class depending on position, but result is messy and incorrect..
Any ideas? Thanks!
The view file:
<ul>
<?php foreach ($categories as $category) { ?>
<?php if($category['children']) { ?>
<li class="bu">
<?php } else { ?>
<li class="onit" >
<?php } ?>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active" ><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li class="onit" >
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>