Magento:get Categories树don';不显示隐藏的类别

Magento:get Categories树don';不显示隐藏的类别,magento,Magento,我使用以下代码显示分类树: $rootcatId= Mage::app()->getStore()->getRootCategoryId(); $categories = Mage::getModel('catalog/category')->getCategories($rootcatId); function get_categories($categories) { $array= '<ul>'; foreach($categories

我使用以下代码显示分类树:

$rootcatId= Mage::app()->getStore()->getRootCategoryId(); 
$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>'.
        $category->getId().' <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); 
$rootcatId=Mage::app()->getStore()->getRootCategoryId();
$categories=Mage::getModel('catalog/category')->getCategories($rootcatId);
函数get_categories($categories){
$array='
    '; foreach($categories作为$category){ $cat=Mage::getModel('catalog/category')->load($category->getId()); //$count=$cat->getProductCount(); $array.='
  • '。 $category->getId()。\n; 如果($category->hasChildren()){ $children=Mage::getModel('catalog/category')->getCategories($category->getId()); $array.=获取类别($children); } $array.='
  • '; } 返回$array。“
”; } echo获取_类别($categories);
如何修改它以递归方式显示隐藏的类别


非常感谢。

您可以不使用getCategories()方法而设置自定义集合。这将显示隐藏的类别,除非另有说明

例如:

$categories = Mage::getModel('catalog/category')
->load(Mage::app()->getStore()->getRootCategoryId())
->getCollection()
->addAttributeToSort('position', 'ASC')
->addFieldToFilter('parent_id',Mage::app()->getStore()->getRootCategoryId())
->addFieldToFilter('include_in_menu',1)
->addAttributeToSelect('name')

您可以设置自定义集合,而不是使用getCategories()方法。这将显示隐藏的类别,除非另有说明

例如:

$categories = Mage::getModel('catalog/category')
->load(Mage::app()->getStore()->getRootCategoryId())
->getCollection()
->addAttributeToSort('position', 'ASC')
->addFieldToFilter('parent_id',Mage::app()->getStore()->getRootCategoryId())
->addFieldToFilter('include_in_menu',1)
->addAttributeToSelect('name')