Magento 顶级类别列表
Magento top level Category list
我需要在 Magento 1.9 站点中创建类别轮播。如何通过 PHP 获取顶级类别列表?
这应该会为您提供顶级类别列表
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')//or you can just add some attributes
->addAttributeToFilter('level', 2)//2 is actually the first level, default is 1
->addAttributeToFilter('is_active', 1)//if you want only active categories
;
现在 foreach
和 $categories
一起打印并以轮播的方式打印。
要获取当前商店的顶级类别,请查找商店根类别的所有直接子类别:
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
$topLevelCategories = $rootCategory->getChildrenCategories();
$topLevelCategories
现在是活跃顶级类别的集合。
我需要在 Magento 1.9 站点中创建类别轮播。如何通过 PHP 获取顶级类别列表?
这应该会为您提供顶级类别列表
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')//or you can just add some attributes
->addAttributeToFilter('level', 2)//2 is actually the first level, default is 1
->addAttributeToFilter('is_active', 1)//if you want only active categories
;
现在 foreach
和 $categories
一起打印并以轮播的方式打印。
要获取当前商店的顶级类别,请查找商店根类别的所有直接子类别:
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
$topLevelCategories = $rootCategory->getChildrenCategories();
$topLevelCategories
现在是活跃顶级类别的集合。