Magento:显示所有level2类别

时间:2013-03-19 23:17:05

标签: magento

我有4个等级的类别 示例:
level0category --> level1category --> level2category -->lastlevel_level3cateogory
是否可以在lastlevel上显示level2中的类别? (在我加载自定义left.phtml的块上)
我正在考虑使用自动类别检测,而不必设置cat_id =

编辑:这是我在寻找的,来自不同来源的混合代码。

<?php
    $currentCat = Mage::registry('current_category');

    if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
    {
        // current category is a toplevel category
        $loadCategory = $currentCat;
    }
    else
    {
        // current category is a sub-(or subsub-, etc...)category of a toplevel category
        // load the parent category of the current category
        $loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
        // @TODO enhance for more nested category levels to display sub-categories
    }    
    $subCategories = explode(',', $loadCategory->getChildren());

    foreach ( $subCategories as $subCategoryId )
    {
        $cat = Mage::getModel('catalog/category')->load($subCategoryId);


if ($cat->getIsActive())
{
    if ($currentCat->getEntityId() == $subCategoryId)
    {
        echo '<li style="display:none;">'.$cat->getName().'</li>';
    }
    else
    {


  echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a> <br>';    }
}

    }
?>

1 个答案:

答案 0 :(得分:1)

$categories = Mage::getModel('catalog/category')
                    ->getCollection()
                    ->addAttributeToSelect('*')
                    ->addIsActiveFilter()
                    ->addAttributeToFilter('level',2)
                    ->addOrderField('name');

确保此行存在

apply ->addAttributeToFilter('level',2)