Display Category Name in Sidebar & on Product Pages
A couple of simple code snippets for you this week on the Magento Blog. Something that’s come up recently is needing to display the category of a product on either the product page, or in the sidebar (for example above the subcategories).
To add the current category name to the sidebar, use the following:
<?php $currentCategory = Mage::registry('current_category'); $currentCategory = $currentCategory->getName(); echo $currentCategory; ?>
To display the parent category of your current product, this option works well:
<?php echo $this->getProduct()->getCategory()->getName() ?>
There are several ways to bring out the category name, however using the above method will mean that you only get the current category of the product, rather than all the categories that the product may be in.
Thanks for visiting ecommerce web design, don’t forget to check back next week for more Magento tips and tutorials. Oh, and Happy Halloween (for Sunday!)