Thursday 10 December 2015

How to get subcategories of current category in magento?

Display all the subcategories of any category in Magento.


If you have a category ID (current category OR any category) then you can easily display all the subcategories of that particular category.


Below code will load all the subcategories of the current category. 


If you want to get all the subcategories of any specific category, so assign category id in $categoryID. 



<?php 
         
       $catID = $current_category->getId(); //or any specific category id, e.g. 5

       $children = Mage::getModel('catalog/category')->getCategories($catID);

       foreach ($children as $category) 

         {
          
           echo $category->getId();
      
           echo $category->getName();
    
           echo $category->getRequestPath();
     
          print_r($category->getData());

}

?>

3 comments:

  1. I was looking for this kind of blogs of getting subcategories of current which is very useful. keep updating the post.
    buy neelambri sapphire online

    ReplyDelete
  2. Really good to know about the subcategories of the current category. Thanks for sharing this post and keep updating.
    coenzyme q10 supplement

    ReplyDelete