我在菜单中有自定义链接,在下拉菜单中显示类别。为此,我在catalog/navigation->mainmenu.phtml
(自定义文件)中创建了一个文件,现在,我想在按名称排序后显示类别。请帮助我如何按名称对类别集合进行排序。我已经在管理员中设置了类别顺序。但在前端它显示未排序。
代码是: -
<?php $defaultcategory= Mage::app()->getStore()->getRootCategoryId();?>
<?php $mainchildren = Mage::getModel('catalog/category')->getCategories($defaultcategory);?>
<ul>
<?php foreach ($mainchildren as $subcategory) : ?> <?php // 2 level ?>
<?php if($subcategory->getIsActive()):?>
<li id="show_subcat" class="<?php if($i==1): echo 'first'; endif; ?>" >
<?php $childid=$subcategory->getId();?>
<?php $subchild = Mage::getModel('catalog/category')->getCategories($childid);?>
<?php foreach ($subchild as $subchildcategory) : ?>
<?php $path=$subchildcategory->getRequestPath()?>
<?php break;?>
<?php endforeach ?>
<a href="<?php echo $this->getUrl().$path; ?>">
<?php echo $name= $subcategory->getName().$subcategory->getEnable() ?>
</a>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>