Search This Blog

Mar 22, 2011

How to display sub-category in Magento in PHTML

It is quite necessary to display the subcategories in your magento store for easy navigation purposes. Sometimes customers are so lazy to go deep in your navigation in which they can’t reach your deepest navigation.
So to display subcategories in magento, the following code is working well.

You might also want these:

Code to display subcategory in Magento:

 $_category  = $this->getCurrentCategory(); 
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper     = Mage::helper('catalog/category');
    <?foreach ($collection as $cat):?>
                <?php if($_category->getIsActive()):?>
                     $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
                     $_img = $cur_category->getImageUrl();  
                                <a href="<?php echo $helper->getCategoryUrl($cat);?>">
                                     <img src="<?php echo $_img?>" title="$cat->getName()"/>
                                     <cite><?php echo $cat->getName();?></cite>
                <?php endif?>
    <?php endforeach;?>


Laurent @ Idealclic said...

Do you know how to display only categories which are "include in navigation Menu" ?

Many thanks.