我正在一个网站上显示与当前类别相关的所有子类别的列表。下面的代码可以正常工作,但我想更改子类别列表的排序方式。目前,它按类别 ID 排序。我希望它以 Magento 用户将类别放入管理员中的任何顺序显示(他们可以拖放以更改类别顺序)。感谢任何帮助!
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a>';
}
}
?>