0

I want current category name on product view Page.

How to get current category name on product view Page?

1

A product can be attached with multiple category so directly not able to get current category of that product but if you visit category page and then goes to product page at that time category is in session so you can get category by

$_category_detail=Mage::registry('current_category');
echo  $_category_detail->getName(); 

if you are directly landing on a product page without accessing any category then there is no category in session so at that time you can get category of that product by

$categoryIds = $_product->getCategoryIds();

    if(count($categoryIds) ){
        $firstCategoryId = $categoryIds[0];
        $_category = Mage::getModel('catalog/category')->load($firstCategoryId);

        echo $_category->getName();
    }
| improve this answer | |
  • In this i get first level current category but i want lower level category as current category. – Deep Shah Feb 14 at 6:47
  • You can reverse the category array. array_reverse( $_product->getCategoryIds() ); – rahul Chittora Feb 14 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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