Magento – Display only sub categories of particular category

category

Here is the code which displays all the categories and sub categories

<?php echo $this->renderCategoriesMenuHtml(TRUE, 0, 'level-top'); ?>

I would like to display only subcategories of category id 10.

Best Answer

IN the below code you pass the category ID's like 4 and got all the subcategories of category.

   <?php
    $cat = Mage::getModel('catalog/category')->load(4);
    $subcats = $cat->getChildren();

    foreach(explode(',',$subcats) as $subCatid)
    {
      $_category = Mage::getModel('catalog/category')->load($subCatid);
      if($_category->getIsActive()) {
        echo '<ul><a href="'.$_category->getURL().'" title="View the products for the "'.$_category->getName().'" category">'.$_category->getName().'</a>';
        $sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
        $sub_subcats = $sub_cat->getChildren();
        foreach(explode(',',$sub_subcats) as $sub_subCatid)
        {
              $_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
              if($_sub_category->getIsActive()) {
                  echo '<li class="sub_cat"><a href="'.$_sub_category->getURL().'" title="View the products for the "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
                  $sub_sub_cat = Mage::getModel('catalog/category')->load($sub_subCatid);
                  $sub_sub_subcats = $sub_sub_cat->getChildren();
                  foreach(explode(',',$sub_sub_subcats) as $sub_sub_subCatid)
                  {
                    $_sub_sub_category = Mage::getModel('catalog/category')->load($sub_sub_subCatid);
                    if($_sub_sub_category->getIsActive()) {
                        echo '<li class="sub_cat"><a href="'.$_sub_sub_category->getURL().'" title="View the products for the "'.$_sub_sub_category->getName().'" category">'.$_sub_sub_category->getName().'</a></li>';
                    }
                  }
               }
         }
         echo '</ul>';
      }
    }

    ?>


        ?>
Related Topic