我有代码按ID在magento中输出类别,但希望这些结果按字母顺序输出。谁能提出什么建议?
<?php
$parentCategoryId = 201;
$cat = Mage::getModel('catalog/category')->load($parentCategoryId);
$subcats = $cat->getChildren();
// Get 1 Level sub category of Parent category
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()) {
echo '<li><a href="'.$_category->getURL().'" title="View the products for the "'.$_category->getName().'" category">'.$_category->getName().'</a>';
echo '</li>';
}
}
?>
您可能想尝试以下代码:
<?php
$parentCategoryId = 201;
Mage::getModel('catalog/category')->getCollection()->addFieldToFilter('parent_id',$parentCategoryId)->addAttributeToSort('name', 'ASC');
让我知道这是否适合您!
快乐编码...