Magento How to get Child Categories by Parent Category id


One thing we will meet for sure in magento is the category. One of the task we will need to do is the listing of child categories, the subcategories. In the following example will be listed the subcategories of a category given by it’s ID.
    <ol>
    <?php
    $parent_category = Mage::getModel('catalog/category')->load(15);
    $subcategories = $parent_category->getChildrenCategories();
    foreach ($subcategories as $child)
    {
     echo "<li><a href=\"".$child->getUrl()."\">" . $child->getName();
     echo   "</a>(".$child->getProductCount().")";
     echo "</li>";
    }
 
    ?>
    </ol>
You can check out the following working example for category subcategories.

1 comments:

November 7, 2016 at 5:55 AM comment-delete

Post a Comment