Magento - Get the Current Category

Need to get the current category loaded? No problem! Just use this useful little snippet below. It will return an object of the current category.

<?php
    $currentCategory = Mage::registry('current_category');
?>

10 comments for Magento - Get the Current Category

Daniel Z's picture

i love your little magento...

i love your little magento zend php posts. they are very informative. please dont stop! i have very little zend experience and these are very helpful for my magento projects

Richard's picture

Daniel, Thanks!...

Daniel, Thanks!

Josh Ribakoff's picture

Thanks, God I hate static and...

Thanks,

God I hate static and implicit interfaces.

Acrobatic's picture

These snippets are great......

These snippets are great... they've helped me multiple times -- thanks!

Richard's picture

Acrobatic, Thanks!...

Acrobatic, Thanks!

Enes's picture

Dumb question sorry but, how...

Dumb question sorry but, how do I show this now on the product page? echo doesn't work Sad

Phil's picture

Enes, if you still need to...

Enes, if you still need to know:

Mage::registry('current_category')->getName()

will get you the name.

Christian's picture

There's an error on product...

There's an error on product page when you search a product. How to fix that bug?

Patrick's picture

Thanks for the snippet, I'm...

Thanks for the snippet,

I'm searching for a way to give the main div an id what's chances whit the category

can i also get the title ore description this way

i tried

Mage::registry('current_category')->getTitle();

but this doesn't work

Rahul's picture

Thanks.I was doing using loop...

Thanks.I was doing using loop but your solution is perfect.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.