简体   繁体   中英

Simple magento category question

How can I stop getChildren() being recursive?

$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 :-

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

For more:- Get list of all categories

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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