0

I added categories unordered list on product page with the following code

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

        ?>

I use some "service" categories and for this I set "not included in menu and in category list"

Is it possible to hide this "special categories" from the product detail list?

2 Answers 2

2

Add this to your filters:

->addAttributeToFilter('include_in_menu', array('eq'=>1))
1
  • Consider adding full code snippet. Oct 9, 2015 at 1:27
0

Try below code

<?php
$currentCatIds = $_product->getCategoryIds();
$categoryCollection = Mage::getModel('catalog/category')->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('include_in_menu', array('eq'=>true))
        ->addIdFilter($currentCatIds)
        ->addIsActiveFilter();
?>

You will need to use ->addAttributeToFilter('include_in_menu', array('eq'=>true)) which is default attribute filter function in Magento.

For addIdFilter($currentCatIds), there is default function in category resource class.

Class: Mage_Catalog_Model_Resource_Category_Collection

Function: addIdFilter($categoryIds)

Param: array $categoryIds

2
  • okay cool.. what is the difference between your answer and Taylor's ? Can you justify ? Oct 9, 2015 at 5:02
  • Edited description in my answer Oct 9, 2015 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.