1

我有 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>';    }
}

    }
?>
4

1 回答 1

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

确保这条线在那里

apply ->addAttributeToFilter('level',2)
于 2013-03-20T04:20:58.833 回答