Magento, echo the current category of a product, on the product page view.phtml

www_puertoricoautoforo_com
www_puertoricoautoforo_com used Ask the Experts™
on
Here's what I need:

I'm editing view.phtml and I would like to echo the category that the current product exists in.

<?php
echo "This product is in the". $current_category;
?>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I tried that but it did not work for the category, my version is 1.3.2.4 btw
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Here is how its done. Just a note, sometimes you can view a product out side a category. For example if you reach it by a search result it will not be considered in a category.
<?php
//Get current category from registry
$currentCategory = Mage::registry("current_category");

//Now just do with it what you will.
//Lets see what  is in the data
//To get the name is is 
$currentCategory->getName();


?>

Open in new window

When I go to a category, it gives me an error about line 8
<?php
//Get current category from registry
$currentCategory = Mage::registry("current_category");

//Now just do with it what you will.
//Lets see what  is in the data
//To get the name is is 
$currentCategory->getName();
?>

Open in new window

ooops nevermind... IT WORKS!! THANKS!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial