我想在产品页面中显示相关类别。
我的产品包含猫A和相关产品猫是猫B,猫C和猫D.
答案 0 :(得分:0)
看看这对你有帮助,
我们假设您已在变量$ category中拥有当前类别。 这段代码应该为您提供所有(活动)类别的兄弟姐妹。
$siblings = Mage::getModel('catalog/category')->getCollection()->setStoreId(Mage::app()->getStore()->getId());
$siblings->addAttributeToSelect('*')
->addAttributeToFilter('parent_id', $category->getParentId()) //siblings have the same parent as the current category
->addAttributeToFilter('is_active', 1)//get only active categories
->addAttributeToFilter('entity_id', array('neq'=>$category->getId()))//exclude current category
->addAttributeToSort('position');//sort by position
现在你可以遍历兄弟姐妹并列出它们:
<?php foreach ($siblings as $sibling): ?>
<a href="<?php echo $sibling->getUrl();?>"><?php echo $sibling->getName();?></a><br />
<?php endforeach;?>
参考文献: https://magento.stackexchange.com/questions/1303/how-to-show-category-siblings