使用下面的代码,我尝试从ID为7的特定父类别中获取子类别。
<?php
$rootCatId = Mage::app()->getStore()->getRootCategoryId();
function getTreeCategories($parentId, $isChild){
$allCats = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('is_active','1')
->addAttributeToFilter('include_in_menu','1')
->addAttributeToFilter('parent_id',array('eq' => $parentId));
$class = ($isChild) ? "sub-cat-list" : "cat-list";
$html .= '<ul class="'.$class.'">';
foreach($allCats as $category)
{
$html .= '<li>'.$category->getName()."";
$subcats = $category->getChildren();
if($subcats != ''){
$html .= getTreeCategories($category->getId(), true);
}
$html .= '</li>';
}
$html .= '</ul>';
return $html;
}
$catlistHtml = getTreeCategories($rootCatId, false);
echo $catlistHtml;
?>
使用此代码显示所有类别。我如何才能从ID为7的特定类别中获取此树?
迈克尔
答案 0 :(得分:0)
试试这个。我希望你得到结果。
$children = Mage::getModel('catalog/category')->getCategories(7);
foreach ($children as $category) {
echo $category->getName();
}
更多帮助here