gpt4 book ai didi

php - Magento:显示子类别列表

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:52:00 25 4
gpt4 key购买 nike

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

我有一个 ID 为 42 的“品牌”类别,我想显示子类别列表并确保每个子类别都链接到 CMS 中指定的 URL 键。

有没有人有使用 Magento 做这件事的经验?

最佳答案

如果您愿意编辑您的主题,此代码片段将为您带来当前类别的所有子类别的列表(来自 session ,因此这应该适用于您的主题中的任何位置)。我通常在 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>

关于php - Magento:显示子类别列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1820012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com