2016-01-20 68 views
0

我有代码输出在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>'; 
    } 
} 
?> 

回答

0

你可能想尝试下面的代码:

<?php 
    $parentCategoryId = 201; 

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

让我知道这对你的作品!

快乐编码...