我想在产品页面中显示相关类别。
我的产品包含猫 A,相关产品猫是猫 B、猫 C 和猫 D。
看看这是否可以帮助你,
假设变量$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