Javascript 如何在magento的产品页面上显示相关类别名称
我想在产品页面中显示相关类别Javascript 如何在magento的产品页面上显示相关类别名称,javascript,php,wamp,magento-1.8,Javascript,Php,Wamp,Magento 1.8,我想在产品页面中显示相关类别 我的产品包含类别A,相关产品类别为类别B、类别C和类别D。看看这是否能帮助您, 假设变量$category中已有当前类别。 这段代码应该为您提供所有(活动)类别同级 $siblings = Mage::getModel('catalog/category')->getCollection()->setStoreId(Mage::app()->getStore()->getId()); $siblings->addAttributeTo
我的产品包含类别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;?>
参考资料: