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:

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

1 comments:

Laurent @ Idealclic said...

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

Many thanks.