0

我试图显示所有二级类别,我的代码是

<?php $storeId    = Mage::app()->getStore()->getId();

//Get category model
$_category = Mage::getModel('catalog/category')->setStoreId($storeId);

$_categoryCollection = $_category->getCollection();
$_categoryCollectionIds = $_categoryCollection->getAllIds();

//Remove root category from array
unset($_categoryCollectionIds[0], $_categoryCollectionIds[1]);

?>

<div id="accordian_hover">
<?php

$o = null;
$o .= '<ul>';

foreach ($_categoryCollectionIds as $catId) {

    $_category = $_category->load($catId);

        if($_category->getLevel() == 2) {

            $catChildren = $_category->getChildren();          

                if(!empty($catChildren)) {
                    $o .= '<li> <a href="'.$_category->getUrl().'">'.$_category->getName().'</a>';
                    $o .= '<ul>';

                    $categoryChildren = explode(",", $catChildren);

                    foreach ($categoryChildren as $categoryChildId) {

                        /* @var $_childCategory Mage_Catalog_Model_Category */
                        $_childCategory = $_category = Mage::getModel('catalog/category')->setStoreId($storeId)->load($categoryChildId);

                        $o .= '<li><a href="'.$_childCategory->getUrl().'">'.$_childCategory->getName().'</a></li>';

                        // If you wish to display the total number of products for each category, uncomment this line
                        // $o .= '<span class="totalNumberOfProducts">'.$_childCategory->getProductCollection()->count().'</span>';

                    }

                    $o .= '</ul></li>';
                }   

        }
    } $o .='</ul>';


echo $o;
?>
</div>

但是顶部菜单 url 错误,其他所有显示正确,但主要类别 url 错误(第二类)请帮助我,当用户将鼠标悬停在类别上时,我也必须显示第三级菜单... Live Link http: //toolskaart.com/

4

1 回答 1

0

希望下面的代码能解决你的问题。

Mage::getModel('catalog/category')->load($_category->getId())->getUrl()

这个对我有用。

于 2015-08-28T09:49:22.520 回答