I want a list of categories with under each categoryname their children categories. But my code isn't working, the top categories are showing but
<ul class="sub"></ul>
is empty, so the children are not showing.
This is my code:
$categoryCollection = Mage::getResourceModel('catalog/category_collection')
->addFieldToFilter('level',2)
->addAttributeToSelect('name')
->addAttributeToSelect('url');
$out = "<ul>";
foreach($categoryCollection as $cat){
$children = $cat->getChildren();
$out .= "<li>";
$out .= "<b><a href='".$cat->getUrl()."'>".$cat->getName()."</a></b>";
$out .="<ul class='sub'>";
foreach($children as $child){
$ChildModel = Mage::getModel('catalog/category')->load($child)
->addAttributeToSelect('name');
$out .="<li><a href='".$ChildModel->getUrl()."'>".$ChildModel->getName()."</a></li>";
}
$out .="</ul>";
$out .= "</li>";
}
$out .= "</ul>";
echo $out;