Magento Sort Categories Alphabetically

吃可爱长大的小学妹 提交于 2020-01-17 03:00:36

问题


recently I was asked to display top-level categories and its sub-categories on left navigation in alphabetical order.

The code I'am using is

<ul id="demo1" class="nav">
<?php $helper = Mage::helper('catalog/category') ?>
<?php $categories = $helper->getStoreCategories(); ?>
<?php foreach ($categories as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>

Unfortunately it displays the categories but not alphabetically.

Also is it not displaying because I am using category helper function ?

Is there any built-in function to display Categories and its Sub-categories in alphabetical order ?

Thanks


回答1:


Remove:

<?php $categories = $helper->getStoreCategories(); ?>

Add:

// sorted by name, fetched as collection
$categories = $helper->getStoreCategories('name', true, false);

// sorted by name, fetched as array
$categories = $helper->getStoreCategories('name', false, false);

Hope will help!



来源:https://stackoverflow.com/questions/20470850/magento-sort-categories-alphabetically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!