Tuesday 22 December 2015

How to get category name by product id in magento?

You can get category name by product id by following code. Where You want display category name, put the code.


<?php $product = Mage::getModel('catalog/product')->load($_product->getId());
$cats = $product->getCategoryIds();
foreach($cats as $categoryId) {
    $category = Mage::getModel('catalog/category')->load($categoryId);
    echo $category->getName();
}
?>



6 comments:

  1. This post is pretty good actually and it has very important information.
    Thank you for this kind of post.
    Buy kashmiri neelam online

    ReplyDelete
  2. This post is very important for the magento developer and its very useful code about the category name. Thanks for sharing and keep updating.
    Transplantation

    ReplyDelete
  3. Thanks for this kind of posts, really appreciated.
    japanese red coral online

    ReplyDelete