我需要在Magento 1.9网站上创建一个类别的轮播。如何通过PHP获取顶级类别列表?
答案 0 :(得分:1)
这应该是你的顶级类别列表
$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
并打印以使其成为旋转木马。
答案 1 :(得分:0)
要获取当前商店的顶级类别,请查找商店根类别的所有直接子类:
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
$topLevelCategories = $rootCategory->getChildrenCategories();
$topLevelCategories
现在是有效顶级类别的集合。