Showing posts with label Get sub category in Magento. Show all posts
Showing posts with label Get sub category in Magento. Show all posts

Thursday, 10 December 2015

How to get sub categories by parent category id in Magento?

You can try below code for display all sub category of one particular category by category id.



<?php 

$category_id = 13;   // you can change category id according to you


$parentCat = Mage::getModel('catalog/category')->load($category_id); 


$subCat = explode(',',$parentCat ->getChildren()); 


$collection  = $parentCat
             ->getCollection()
             ->addAttributeToSelect("*")
             ->addFieldToFilter("entity_id", array("in", $subCat) );


foreach($collection as $catname)

{

     echo $catname->getName();


}


?>