Displaying subcategories from the categories in magento

Category/Subcategory management feature is already provided by Magento through their admin section. If someone is required to display all subcategories from any particular category that usually required in order to match the requirement of the project. Then you can use the code below to perform this task.

If you are adding more category from Magento Admin
>>Catalog >>Manage Categories Option

and want to see all the subcategory of any specific category then we need to write down following code

$service_category = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*')
->addIsActiveFilter()
->addLevelFilter(1)
->addOrderField('Service Category');
foreach($service_category as $category)
{
if($category->getId()==74)
{

foreach ($category->getChildrenCategories() as $subcat) {

// echo"<br>catname=".$subcat->getName()." and id=".$subcat->getId();
echo "<input type="checkbox" name ="blog_category" value="".$subcat->getId()."">".$subcat->getName()."<br>";
}
}

}

Here you can see i have added if($category->getId()==74) to find the id of this specific category simply you need to go to Magento Admin >> Catalog >> Manage Categories
Here you will see the listing on all categories if you will try to edit any category you will see id of that category will already come to your browser’s URL; If you want to see list of all the categories then you can just delete this condition.

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...