Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在magento的产品页面上显示相关类别名称_Javascript_Php_Wamp_Magento 1.8 - Fatal编程技术网

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;?>


参考资料: