问题
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