Magento:显示子类别列表 [英] Magento: Display sub-category list
问题描述
我正在建立一个Magento商店,希望能够显示类别列表,并使每个类别链接到其自己的页面.
I'm building a Magento store and want to be able to display a list of categories and have each category link to its own page.
我有一个ID为42的品牌"类别,我想显示一个子类别列表,并确保每个链接到CMS中指定的URL密钥.
I have a 'Brands' category with an ID of 42 and I want to display a list of the sub-categories and ensure that each one links to the designated URL key in the CMS.
有没有人有过与Magento一起做这件事的经验?
Has anyone had experience of doing this with Magento?
推荐答案
如果您方便地编辑主题,此代码段将为您带来当前类别的所有子类别的列表(来自会话,因此应该可以在您的主题中的任何地方使用).我通常在app/design/frontend/default/ theme_name /template/catalog/category/view.phtml
If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in 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>
这篇关于Magento:显示子类别列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!