如何获取magento中的所有3个级别的类别?

时间:2014-05-07 11:30:51

标签: php magento

我想显示所有顶级类别及其各自的2级子类别。例如 根类别(id = 3)

-Electronics
  --Computers
   ---Dell
   ---Samsung
   ---Accer

 -Games Movies and Musics
  --Games
   ---Pc Games
   ---Mobile Games

此处电子游戏电影和音乐是顶级类别 我不想显示根类别,只有顶级类别,即来自电子产品游戏电影和音乐

1 个答案:

答案 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>';
            }
        }

    }