Magento:显示子类别列表

dou*_*ood 4 php magento magento-1.9

我正在建立一个Magento商店,希望能够显示一个类别列表,并让每个类别链接到自己的页面.

我有一个ID为42的'品牌'类别,我想显示子类别列表,并确保每个子类别链接到CMS中指定的URL密钥.

有没有人有与Magento这样做的经验?

小智 17

如果您对编辑主题感到满意,此代码段将为您提供当前类别的所有子类别的列表(来自会话,因此这应该适用于您主题中的任何位置).我通常在app/design/frontend/default/theme_name /template/catalog/category/view.phtml中使用它

<?php
$_category  = $this->getCurrentCategory(); 
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper     = Mage::helper('catalog/category');
?>

<ul>
    <?php foreach ($collection as $cat):?>
            <?php if($_category->getIsActive()):?>
                <?php 
                     $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
                     $_img = $cur_category->getImageUrl();  
                ?>
                <li>
                    <a href="<?php echo $helper->getCategoryUrl($cat);?>">
                         <img src="<?php echo $_img?>" title="<?php echo $cat->getName();?>"/>
                         <cite><?php echo $cat->getName();?></cite>
                    </a>
                </li>
            <?php endif?>
    <?php endforeach;?>
</ul>
Run Code Online (Sandbox Code Playgroud)