Magento - list sub-categories of a specific parent category as links
10,372
Solution 1
Please try this code I think you did this code but this is very helpful for someone who is searching this code
<?php
$children = Mage::getModel('catalog/category')->getCategories(3);
foreach ($children as $category):
$category = Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
endforeach;
?>
Solution 2
I don't know why @Dhanapal solution has not worked for me, so I used:
$categories = Mage::getModel('catalog/category')->load('3')->getChildrenCategories();
foreach ($children as $category):
$category = Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
endforeach;
Author by
Kayla
Updated on June 04, 2022Comments
-
Kayla almost 2 years
I am a beginner to php and am stuck on trying to call out sub-categories of just one parent category as links
I got to this and it’s bringing up the getName but the getUrl() isn’t returning any URL at all....
<?php $children = Mage::getModel('catalog/category')->getCategories(3); foreach ($children as $category): echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>'; endforeach; ?>
The output code is just
<li><a href="">name of sub-cat</a></li>
Anybody have any ideas? Please?
Thanks, Kayla