Follow by Email

Friday, July 29, 2011

Show subcategory in a category page

If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml

= $this->getCurrentCategory();
= Mage::getModel('catalog/category')->getCategories($_category->entity_id);
= Mage::helper('catalog/category');

<?foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
= Mage::getModel('catalog/category')->load($cat->getId());
= $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;?>

No comments:

Post a Comment