I want to show all top level categories and its respective 2 level of subcategories. for example Root category(id=3)
-Electronics
--Computers
---Dell
---Samsung
---Accer
-Games Movies and Musics
--Games
---Pc Games
---Mobile Games
Here Electronics and Games Movies and Musics is top level categories I don't want to display root category, only from top level categories i.e from electronics and Games Movies and Musics
Like this
$category_id = 'Electronics category id'
$children = Mage::getModel('catalog/category')->getCategories($category_id);
foreach ($children as $category) {
echo $category->getName();
}
Update: You can keep looping through them like this
$category_id = 'Electronics category id';
$children = Mage::getModel('catalog/category')->getCategories($category_id);
foreach ($children as $category) {
echo '<h1>'.$category->getName().'</h1>';
if($category->getChildren()){
$childrensChildren = $category->getChildren();
foreach($childrensChildren as $ChildCategory){
echo '<h2>'.$ChildCategory->getName().'</h2>';
}
}
}