Magento输出类别和子类别按字母顺序排列

时间:2016-01-20 13:56:06

标签: php magento

我有代码通过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>';
  }
}
?>

1 个答案:

答案 0 :(得分:0)

您可能需要尝试以下代码:

 <?php 
    $parentCategoryId = 201;

    Mage::getModel('catalog/category')->getCollection()->addFieldToFilter('parent_id',$parentCategoryId)->addAttributeToSort('name', 'ASC');

请告诉我这是否适合您!

快乐编码......