【发布时间】:2015-05-15 21:07:03
【问题描述】:
我想在产品页面显示相关类别。
我的产品包含猫 A,相关产品猫是猫 B、猫 C 和猫 D。
【问题讨论】:
标签: javascript php wamp magento-1.8
我想在产品页面显示相关类别。
我的产品包含猫 A,相关产品猫是猫 B、猫 C 和猫 D。
【问题讨论】:
标签: javascript php wamp magento-1.8
看看能不能帮到你
假设您已经在变量 $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
【讨论】: