2012-03-15 116 views
0

我看了以前提出和回答螺纹:Magento display all categories on product view page with parent categoriesMagento的:显示类别的产品属于不同的产品页面,但滤出一种特定的类别

与代码:

$currentCatIds = $_product->getCategoryIds(); 
$categoryCollection = Mage::getResourceModel('catalog/category_collection') 
        ->addAttributeToSelect('name') 
        ->addAttributeToSelect('url') 
        ->addAttributeToFilter('entity_id', $currentCatIds) 
        ->addIsActiveFilter(); 
foreach($categoryCollection as $cat){ 
    echo $cat->getName().' '.$cat->getUrl(); 
} 

的代码做添加类别链接到我的产品页面,这是我想要的。

但我有一个名为“默认类别”的特定类别,其他所有类别都在其下。无论如何,我可以过滤“默认分类”并将其隐藏在产品页面中?

我在PHP很糟糕,所以请帮助我。

非常感谢您

马库斯

回答

0

尝试增加类别级别的过滤器。 默认分类有水平= 1,孩子得+1

$categoryCollection = Mage::getResourceModel('catalog/category_collection') 
       ->addAttributeToSelect('name') 
       ->addAttributeToSelect('url') 
       ->addFieldToFilter('level', array('gteq' => 1)); 
       ->addAttributeToFilter('entity_id', $currentCatIds) 
       ->addIsActiveFilter(); 
0

如果您需要列出所有相关的产品视图页面所选产品的类别,你只需要把下面的代码在app/design/frontend /// template/catalog/product/view.phtml

<?php $categories = $_product->getCategoryIds(); ?> 
    <?php foreach($categories as $k => $_category_id): ?> 
    <?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?> 
< <a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a> 
    <?php endforeach; ?> 
相关问题