Again I had to learn how much magento e-commerce documentation sucks or better to say the lack of it. After reading several tutorials and part-conclusions, i found following working solution
First of all it’s important to have one default category as a root category. Then you can use the following code in “magento/app/design/frontend/<#your template#>/<#your layout#>/template/catalog/navigation/top.phtml”.
<div id="navi"> <ul> <?php foreach ($this->getStoreCategories() as $key => $cat): if ($this->isCategoryActive($cat)) { echo '<li class="active"> <a href="'.$this->getCategoryUrl($cat).'"> <span>'.$cat->getName()."</span></a> </li>\n"; } else { echo '<li class="normal"> <a href="'.$this->getCategoryUrl($cat).'"> <span>'.$cat->getName()."</span></a> </li>\n"; } endforeach; ?> </ul> </div>
Be sure to use $this->isCategoryActive() instead of finding out the current category first and compare it with the active one. This wouldn’t work for sub-categories so that an active sub-category wouldn’t mark it’s parent active. Actually many tutorials seem to have that mistake in their code.
A more or less good resource for magento developers is magetips.com.
I found the adressed function there as well.
