tags:

views:

49

answers:

1

In Magento on each products detail page I would like to list which categories which belongs to.

How would I go about achieving this?

+2  A: 

Give this a try:

$currentCatIds = $_product->getCategoryIds();

and also

 $categoryCollection = Mage::getResourceModel('catalog/category_collection')
  ->addAttributeToSelect('name')
  ->addAttributeToSelect('url')
  ->addAttributeToFilter('entity_id', $currentCatIds)
  ->addIsActiveFilter();

Cheers, JD

Jonathan Day
will this work in 1.4? I heard that category_ids attribute was deprecated...
silvo
I used the first method and it worked on Magento 1.4.0.1.
a1anm
@silvo `category_ids` still appears in my `eav_attribute` table with `attribute_id` = 91. Where did you hear about deprecation? I haven't seen an official announcement about any deprecations, it would be interesting to read...
Jonathan Day
@Jonathan: I read about problems with this attribute in the comments to this blog: http://blog.chapagain.com.np/magento-how-to-filter-product-collection-using-2-or-more-category-filters/. However, it seems that it's ok.
silvo