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.
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments