我不会像在管理中那样对类别进行排序,如果我使用getChildren,那么它就不会像在管理中那样排序类别,但是如果我使用getChildrenCategories,那么就没有结果了。
<?php
$cats = Mage::getModel('catalog/category')->load(74)->getChildren();
$catIds = explode(',',$cats);
$categories = array();
foreach($catIds as $catId) {
$category = Mage::getModel('catalog/category')->load($catId);
$categories[$category->getName()] = array(
'url' => $category->getUrl(),
'img' => $category->getImageUrl()
);
}
ksort($categories, SORT_STRING);
?>
<ul>
<?php foreach($categories as $name => $data): ?>
<li>
<a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
<img class="cat-image" src="<?php echo $data['img']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>发布于 2015-11-30 22:32:11
使用一个有序的集合。见下面的例子:
<?php
$category = Mage::getModel('catalog/category')->load(74);
$collection = $category->getCollection();
->addAttributeToSelect('name')
->addAttributeToSelect('image')
->addIdFilter($category->getChildren())
->setOrder('name', Varien_Db_Select::SQL_DESC);然后,可以循环遍历集合以呈现项。
https://stackoverflow.com/questions/33980757
复制相似问题