How to get sub-categories of a specific parent category?

后端 未结 6 1231
余生分开走
余生分开走 2020-12-29 04:30

I had a main category (parent category) whose id = 10. I want to echo just its sub-categories. How can I do that?

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 04:54

    To get all the active as well as inactive sub categories

    $parent_category_id = 10;
    
    $child_categories = Mage::getResourceModel('catalog/category_collection')
                    ->addAttributeToSelect('*')
                   ->addAttributeToFilter('is_active', array('in' => array(0,1)))
                  ->addAttributeToFilter('parent_id', $parent_category_id);
    
    foreach ($child_categories as $cat)
    {
        $sub_category_id = $cat->getId();
        $sub_category_name = $cat->getName();
    }
    

提交回复
热议问题