Get Category tree in magento

Get Category tree (but we must add root category id static)
Here is print category tree. From root category get and all level category print in tree mode.
$parenCateId = 2 is a by default root category ID. load this category and get all children.
use if condition for checking category is active or not. With the foreach loop print all active category. 

Here is code......
<?php 
$parenCateId = 2;
$cate = Mage::getModel('catalog/category')->load($parenCateId);
$subcates = $cate->getChildren();

echo '<ol>';
foreach(explode(',',$subcates) as $subproCatid)
{
  $_category = Mage::getModel('catalog/category')->load($subproCatid);
 if($_category->getIsActive()) {
echo '<li>'.$_category->getName();
$sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
$sub_subcats = $sub_cat->getChildren();
echo '<ol>';
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">'.$_sub_category->getName().'</li>';
 
}
}
echo '</ol>';
echo '</li>';
 }
}
 echo '</ol>';
?>

Labels: