Display a product’s category name

When on a product page in Magento, it can be a bit tricky to display the name of the category the product is in. Actually it’s not that hard, all you have to do is to follow these Magento tips. The template file you’ll have to edit is this one catalog/product/view.phtml and add the next code where you want to display the category
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<a href="/<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?></a>
<?php endforeach; ?>

Site Search

Contact Us

Parent Technology Inc.
1535 Rosalind Rd Se
East Grand Rapids, MI 49506, USA

This email address is being protected from spambots. You need JavaScript enabled to view it.