本文介绍了Magento按字母顺序分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我被要求在左侧导航中按字母顺序显示顶级类别及其子类别.

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

我正在使用的代码是

<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 ?

谢谢

推荐答案

删除:

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

添加:

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

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

希望会有所帮助!

这篇关于Magento按字母顺序分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:36