0

我在类别树的导航下有两个主要的孩子,如下图所示

在此处输入图像描述

在此处输入图像描述

我想列出RegionActivities的类别和子类别,我为此尝试了两种不同的功能

$collection = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name')->load();
    foreach ($collection as $cat) {
        echo $cat->getName();
    }  

这将返回 Region 和 Actities 的所有孩子以及另一个函数

$children = Mage::getModel('catalog/category')->getCategories(10);
foreach ($children as $category) {
  echo $category->getName();
} 

参考链接

这仅返回子类别

我想列出所有类别,子类别和子子类别等等......对于区域

预先感谢

4

1 回答 1

1

试试这个:

    $rootcatId= 10;
    $categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
    function  get_categories($categories) {
        $array= '<ul>';
        foreach($categories as $category) {
            $cat = Mage::getModel('catalog/category')->load($category->getId());
            $count = $cat->getProductCount();
            $array .= '<li>'.
            '<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
                      $category->getName() . "(".$count.")</a>\n";
            if($category->hasChildren()) {
                $children = Mage::getModel('catalog/category')->getCategories($category->getId());
                 $array .=  get_categories($children);
                }
             $array .= '</li>';
        }
        return  $array . '</ul>';
    }
    echo  get_categories($categories); 
于 2012-09-17T11:11:41.853 回答