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 に答える