简体   繁体   English

按字母顺序获取Magento子类别

[英]Get Magento Sub-Categories in Alphabetical Order

I'm using the code below to get all the subcategories of category '9'. 我正在使用下面的代码来获取类别“ 9”的所有子类别。
The code works great, but it sort the subcategory by id or creation date, I need to sort the subcategories alphabetically. 该代码很好用,但是它按ID或创建日期对子类别进行排序,我需要按字母顺序对子类别进行排序。

<?php
$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('parent_id', 9);

foreach ($categories as $cat) { ?>
    <?php 
        $entity_id = $cat->getId();
        $name = $cat->getName();
        $url_key = $cat->getUrlKey();
        $url_path = $cat->getUrlPath();
        $skin_url = $cat->getImageUrl();
    ?>
    <div>
        <a href="<?php echo $url_path ?>">
            <?php 
                echo '<img style="width: 100%;" src="'.$skin_url.'" />';
            ?>

            <div class="brand-border-top"></div>
            <div class="brand-border-bottom"></div>
            <div class="brand-overlay">
                <?php echo $name = $cat->getName(); ?>
            </div>
        </a>
    </div>
<?php } ?>

Use 采用

->addAttributeToSort('name','ASC');

In your case 就你而言

$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('parent_id', 9)->addAttributeToSort('name','ASC');

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

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