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();


}


?> 

3 comments:

  1. I like this kind of posts which includes more informations. This post is one of them. Thank you for this kind of posts, keep updating.
    buy neelambri sapphire online

    ReplyDelete
  2. This post is so informative and pretty well maintained. Thanks for sharing this post, and keep updating.
    coenzyme q10 capsules

    ReplyDelete
  3. Really good to know about the magento, thanks for it.
    umbilical hernia treatment in delhi

    ReplyDelete