There are several things in the code below, first he will get all categories of stores - he then checks to see if they are active before continuing.
Courtesy code: magentocommerce forum
<?php $_main_categories=$this->getStoreCategories(); $_current_category=$this->getCurrentCategory(); $_categorypath = $this->getCurrentCategoryPath(); ?> <ul> <?php if ($_main_categories): foreach ($_main_categories as $_main_category): if($_main_category->getIsActive()): $cur_category=Mage::getModel('catalog/category')->load($_main_category->getId()); $layer = Mage::getSingleton('catalog/layer'); $layer->setCurrentCategory($cur_category); ?> <li><a href="<?php echo $this->getCurrentCategory()->getUrl()?>"><?php echo $this->getCurrentCategory()->getName();?></a></li> <?php if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?> <?php $_maincategorylisting=$this->getCurrentCategory()?> <?php $_categories=$this->getCurrentChildCategories()?> <?php if($_categories->count()):?> <ul> <? foreach ($_categories as $_category):?> <? if($_category->getIsActive()): $cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId()); $layer = Mage::getSingleton('catalog/layer'); $layer->setCurrentCategory($cur_subcategory); ?> <li><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></li> <? endif;?> <?endforeach?> </ul> <?php ?> <?php $layer->setCurrentCategory($_current_category); ?> <?endif;?> <?endif;?> <?php endif; endforeach; else: ?> <p>$_main_categories array was empty.</p> <p>This might be because you are referencing this phtml file with a wrong type attribute. You should use <block type="catalog/navigation" ... /> !</p> <?php endif; ?>
source share