使用getCollection&的Magento类别列表addLevelFilter,但不包括默认根目录类别 [英] Magento categories listing using getCollection & addLevelFilter but exclude Default Root Category

查看:65
本文介绍了使用getCollection&的Magento类别列表addLevelFilter,但不包括默认根目录类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取集合并使用addLevelFilter(2)在一个级别上进行过滤.这完美地输出了我在第2级的所有类别,除了它还会拉动我列表中的Default Root Category.我想将其排除在外,但在浏览了所有可用方法后,我发现没有任何东西可以帮助我删除/排除某些级别或类别.我真的想要一个完整的证明解决方案,因此,如果我选择说第3级,它将只显示第3级,而不显示1,2,3级.有没有人建议只拉某些级别/类别!

I'm using the following code to grab a collection and to filter on a level using addLevelFilter(2). This outputs all my categories at level 2 perfectly except it also pulls through the Default Root Category in my list. I want to exclude this from view but having looked through all the available methods, I see nothing that will help me remove/exclude certain levels or categories. I really want a full proof solution so if I were to choose say level 3 it would only show level three and not level 1,2,3. Does anyone have a suggestion to pull only a certain level/categories!!??

<?php
$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter()
                    ->addLevelFilter(2)
                    ->addOrderField('name');
    foreach($categories as $category):
?>
    <div class="home-cats">
        <div class="product-image">
           <a href="<?php echo $category->getURL() ?>" title="<?php echo $this->htmlEscape($category->getName()) ?>">
             <img src="<?php echo $category->getImageUrl() ?>" width="88" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
           </a>
        </div>
    </div>
<?php endforeach; ?>

任何建议/反馈将不胜感激.干杯,萨胡斯

Any advice/feedback would be greatly appreciated. Cheers, Sahus

推荐答案

您可以尝试

->addAttributeToFilter('level',2)

这可能对您有用

这篇关于使用getCollection&amp;的Magento类别列表addLevelFilter,但不包括默认根目录类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆