Magento Get Child Categories

Magento Get Child Categories: Catalog catgory model Mage::getModel(‘catalog/category’) is used to the child categories of parent category in magento. Using this model you can load the categories in this model. Here in this tutorial we are going to explain how to get child categories of a categories with example.

Magento Get Child Categories

Let us understand how to get child categories with simple example –

Magento get child categories ids

First let us get child categories ids. Here is syntax to get child ids as below-

Magento Get Child Categories

/* First Load category by id*/
$category = Mage::getModel('catalog/category')->load($id);
/*This will Return comma separated ids*/
$subcategories = $category->getChildren();
$subcategoriesArray = explode(',',$subcategories);

The above example will give you comma separated string of ids which you can convert to arrays as above.

More Example

Let us have more example of child categories.

Magento Sub-Categories / Child Categories of parent Category-

You can get sub-categories of specific category as below-

Magento Sub-Categories / Child Categories of parent Category-

$childrenCat = Mage::getModel('catalog/category')->getCategories($id);
foreach ($childrenCat as $category) {
    echo $category->getId()."<br>"; // will give category Id
    echo $category->getName().<br>; // will give category name
    echo $category->getRequestPath(); // will give category path

The above example will you all child categories of the selected categories.


Add Comment

📖 Read More