This question already has an answer here:

How do i get product category url and name on product detail page?

<a href="<?php echo $helper->categoryAttribute($product, $product->getCategory(), 'url'); ?>">
    View All 
    <?php echo $helper->categoryAttribute($product, $product->getCategory(), 'name'); ?></a>

marked as duplicate by Manashvi Birla, sv3n, brentwpeterson, Moose, benmarks Jul 5 '17 at 19:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


try the below code.

    <?php $cat_id = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>
    <?php $category = Mage::getModel('catalog/category')->load($cat_id); ?>
    <?php echo $category->getName(); ?>
    <?php echo $category->getUrl(); ?>


<a href=<?php echo $_category_detail->getUrl();?>>View All <?php echo $_category_detail->getName();?></a>


  • Please accept your own answer if it solved your problem :) – sv3n Jul 10 '17 at 11:26

You can call the model from product ID

$product = Mage::getModel('catalog/product')->load($productId);
$categoryIds = $product->getCategoryIds();

foreach ($categoryIds as $category_id) {
    $_cat = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($category_id);
    echo $_cat->getName(); 
    echo $_cat->getUrl();            
  • This doesn't work if the product is in multiple categories, as the question is about the current product detail page. – Niels Jul 5 '17 at 11:08
  • The foreach loop is there for it ? Why do you think it wont work ? – Priyank Jul 5 '17 at 11:32

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