0
我正在一个网站上显示与当前类别关联的所有子类别的列表。下面的代码正常工作,但我想改变子类别列表的排序方式。目前,它按类别ID排序。我希望它以Magento用户将类别放入管理员的任何顺序显示出来(他们可以通过拖放来更改类别顺序)。感谢任何帮助!更改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>';
}
}
?>
函数是递归的,因为它加载由Children()过滤的集合。请注意,第一个函数getChildren返回一个所有儿童id的字符串,getChildrenCategories返回一个Mage_Catalog_Model_Category的数组。 – dagfr 2013-02-15 19:22:16
感谢您的反馈,我用这些信息更新了我的答案。 – dmanners 2013-02-15 20:07:51
不客气。请注意,主要变化是:不再需要爆炸()和无负载()。更简洁,更简单的代码。 – dagfr 2013-02-15 20:31:32