我尝试使用填充程序显示产品页面中包含的产品类别,因此我只显示某个类别或其子类别中的产品。
我有一个类别(ID 10)我将所有广告系列放在子类别中 在产品级别,我会看到该产品是否属于类别10或其子类别,并且该类别具有指向该类别的可点击链接。
这是我到目前为止所得到的。 下面的代码给出了产品所在的所有类别
<?php
$currentCatIds = $_product->getCategoryIds();
$categoryCollection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('name')
->addAttributeToSelect('url')
->addFieldToFilter('level', array('eq' => 4))
->addAttributeToFilter('entity_id', $currentCatIds)
->addIsActiveFilter();
?>
这是我的输出
<?php foreach($categoryCollection as $cat):?>
<a href="<?php echo $cat->getUrl(); ?>" title="<?php echo $cat->getName(); ?>"><?php echo $cat->getName();?></a></br>
<?php endforeach; ?>