简体   繁体   English

简单magento分类问题

[英]Simple magento category question

How can I stop getChildren() being recursive?如何停止getChildren()递归?

$categories = Mage::getModel('catalog/category')->load(2)->getChildren();

I only want to know the immediate children of a category, not it's grandchildren.我只想知道一个类别的直系孩子,而不是孙子。

Use addLevelFilter :-使用addLevelFilter :-

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter()
                    ->addLevelFilter(1)
                    ->addOrderField('name');

For more:- Get list of all categories更多信息:-获取所有类别的列表

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM