如何在magento 1.9.1

时间:2016-10-24 11:53:11

标签: magento magento-1.9 magento-1.8

我是magento开发人员的新手我在我的域中安装magento但现在我在主页中显示所有类别,但它只显示顶级类别。我想显示所有类别。

2 个答案:

答案 0 :(得分:7)

获取类别和子类别:

<?php 
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
if (count($_categories) > 0){
    foreach($_categories as $_category){
        $_category = Mage::getModel('catalog/category')->load($_category->getId());
        $_subcategories = $_category->getChildrenCategories();
        if (count($_subcategories) > 0){
            echo $_category->getName();
            echo $_category->getId();      
            foreach($_subcategories as $_subcategory){
                 echo $_subcategory->getName();
                 echo $_subcategory->getId();
            }
        }
    }
}
?>

只获得一个类别:(根据需要输入类别ID)

<?php
$category = Mage::getModel('catalog/category')->load(4);
$subcategories = $category->getChildrenCategories();
if (count($subcategories) > 0){
    echo $category->getName();
    foreach($subcategories as $subcategory){
        echo $subcategory->getName();
    }
}
?>

答案 1 :(得分:0)

您可以使用以下集合显示所有类别。此代码从catch获取数据。

$categoriesCollection = $helper->getStoreCategories('name', true, false);