Can't get getChildCategories to work when looping through parents
Trying to print out a two tier navigation menu of my categories. For each parent category I would like to print out a list of it's child categories. All the demos I see use Mage::get开发者_运维技巧Model, but trying to get it to work with getChildCategories. Check out the code below, the areas commented out are what is breaking it. Any help would be great.
$nl = chr(10);
$obj = new Mage_Catalog_Block_Navigation();
$main_cats = $obj->getStoreCategories();
echo '<ul>';
foreach ($main_cats as $main) {
// $sub_cats = $this->getChildCategories($main);
$main_class = ($this->isCategoryActive($main)) ? 'current' : '';
echo '<li class="'.$main_class.'"><a href="'.$this->getCategoryUrl($main).'">'.$main->getName().'</a>'.$nl;
/*
if ($sub_cats->count())) {
echo '<ul>';
foreach ($sub_cats as $sub) {
$sub_class = ($this->isCategoryActive($sub)) ? 'current' : '';
echo '<li class="'.$sub_class.'"><a href="'.$this->getCategoryUrl($sub).'">'.$sub->getName().'</a></li>'.$nl;
}
echo '</ul>'.$nl;
}
*/
echo '</li>';
}
echo '</ul>';
What do you think about this?
getting_and_using_categories_and_subcategories
精彩评论