Display all categories and sub categories on left sidebar in Magento

You can display list of all categories and subcategories in left sidebar including product view page using the following code in Magento. You can display subcategories upto second level using this code. You can create a new file for this code and you can add it in your theme’s catalog XML file like this:



It should be placed inside the reference name “left“, to show it in the left sidebar. I hope you know all these stuffs. Let’s get to the point. Just copy and paste the code in the my_left_nav.phtml, which should be in your theme’s catalog/navigation folder.
    <?php $obj = new Mage_Catalog_Block_Navigation(); $storeCategories = $obj->getStoreCategories(); Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId=''; foreach ($storeCategories as $_category): ?>
  • <?php echo $_category->getName(); ?> <?php $categoryChildren = $_category->getChildren(); ?> <?php if($categoryChildren->count()) : ?> <?php endif; ?>
  • <?php endforeach ?>

No comments:

Post a Comment