简体   繁体   English

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

[英]Magento output category and subcategories in alphabetical order

I have the code to output a category in magento by ID, but want these results to be output in alphabetical order. 我有通过ID在magento中输出类别的代码,但希望这些结果以字母顺序输出。 Can anyone suggest anything? 有人可以建议什么吗?

 <?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>';
  }
}
?>

You might want to try the below code: 您可能要尝试以下代码:

 <?php 
    $parentCategoryId = 201;

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

Let me know if this works for you! 让我知道这是否适合您!

Happy Coding... 快乐编码...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM