How to show programmatically category and subcategory from Admin site in Magento?
To show pro grammatically you can display all category and subcategory. Some times it is very important for coder. please check below code.
You can show your category and subcategory own way.
$root_category = Mage::getModel(‘catalog/category’)->load(3); // Put your root category ID here.
$subcategories = $root_category->getChildren();
foreach(explode(‘,’,$subcategories) as $subcategory) {
$category = Mage::getModel(‘catalog/category’)->load($subcategory);
echo ‘Cat 1–<a href=”‘.$category->getURL() .'” />’.$category->getName().$category->getId().'</a><br/>’;
$parentCategoryId = $category->getId(); // set correct parent category id
foreach (Mage::getModel(‘catalog/category’)->load($parentCategoryId)->getChildrenCategories() as $childCategory) {
$parentCategoryId2 = $childCategory->getId(); // set correct parent category id
if(count(Mage::getModel(‘catalog/category’)->load($parentCategoryId2)->getChildrenCategories())>1)
echo ‘Cat 2–<a href=”‘.$childCategory->getURL() .'” />’.$childCategory->getName().$childCategory->getId().'</a><br/>’;
else
echo $childCategory->getName() . ‘ ‘ . $childCategory->getId(). ‘<br />’;
foreach (Mage::getModel(‘catalog/category’)->load($parentCategoryId2)->getChildrenCategories() as $childCategory2) {
echo $childCategory2->getName() . ‘ ‘;
echo $childCategory2->getId() . ‘<br />’;
}
}
}