Skip to main content
deleted 4 characters in body
Source Link
Keyul Shah
  • 7.2k
  • 13
  • 38
  • 60
Source Link
TBI Infotech
  • 4.8k
  • 1
  • 14
  • 30

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>';
      }
    }
    
    ?>
    
    
        ?>