我想显示所有顶级类别及其各自的2级子类别。例如 根类别(id = 3)
-Electronics
--Computers
---Dell
---Samsung
---Accer
-Games Movies and Musics
--Games
---Pc Games
---Mobile Games
此处电子和游戏电影和音乐是顶级类别 我不想显示根类别,只有顶级类别,即来自电子产品和游戏电影和音乐
答案 0 :(得分:0)
喜欢这个
$category_id = 'Electronics category id'
$children = Mage::getModel('catalog/category')->getCategories($category_id);
foreach ($children as $category) {
echo $category->getName();
}
更新: 你可以像这样继续循环它们
$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>';
}
}
}