根据管理中的位置对 Magento 中的类别进行排序
我想知道如何对这个类别列表进行排序(我在这里遵循了本教程 http://www.devinrolsen.com/magento-custom-category-listing-block/)在magento中按管理面板中的位置排列?目前是按id排序
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a>';
?>
</li>
<?php endforeach; ?>
</ul>
I would like to know how to sort this list of categories (I followed this tutorial here http://www.devinrolsen.com/magento-custom-category-listing-block/) in magento by position in the admin panel? Currently it is sorted by id
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a>';
?>
</li>
<?php endforeach; ?>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你为自己处理 ID 之类的事情做了太多的工作。以下内容已按标准按位置排序。
You're making way too much work for yourself trying to deal with IDs and stuff. The following is already sorted by position as standard.
如果您想按 adminhtml 中创建的位置对类别进行排序,则可以在指定所需内容的位置进行查询,因为
catalog/category
是Mage_Catalog_Model_Resource_Category_Collection
的实例选择、过滤和/或排序。这里的情况是从
catalog_category_entity
获取类别,仅选择名称,在ID之后进行过滤,并对位置
的查询进行排序。If you want to sort the categories by the position created in adminhtml you can then, since
catalog/category
is an instance ofMage_Catalog_Model_Resource_Category_Collection
, make a query where you specify what you want to select, filter and/or sort.The case here is getting categories from
catalog_category_entity
select only the name, filtering after the id and sort the query on theposition
.这就是我所做的:
检索类别之后:
然后:
反转返回值(1 和 -1)显然会改变顺序。
它对我来说效果很好。
希望它能帮助某人。
This is what I did:
after to retrieve the categories:
and then:
Inverting the return (1 and -1) would obviously change the order.
It worked just fine for me.
Hope it helps someone.
我强烈建议先看看这里 http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections 以及知识库中的其他文章是任何 magento 开发人员必读的内容。
I strongly suggest to lok here first http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections and also other articles in knowledge base are a must read for any magento dev.