Magento : Get Current Category – Category Id

Posted: June 18, 2010 in Magento, Version 1.3.*
Tags:

$layer = Mage::getSingleton(‘catalog/layer’);
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();

Bijal Bhavsar 🙂

Advertisements
Comments
  1. fishpig says:

    A better way to get the current category is to use:

    $_category = Mage::registry(‘current_category’);

    http://fishpig.co.uk/2010/04/10/the-magento-registry/

  2. awara says:

    That’s good tip, I appreciate your hard work. Please keep it up.
    Thank’s

    Mubashar

  3. […] Magento : Get Current Category – Category Id June 20101 comment 5 […]

  4. Ravi says:

    Very Good Article.

    Thanks
    BharatMatrimony

  5. nacs says:

    thanks ..

  6. Really worked.Thank you very much!!!

  7. tuba says:

    You could use Mage::getModel(‘catalog/layer’)->getCurrentCategory() also

  8. w786zid says:

    thnks .. very good article. it helps me most… thnks again..

  9. Toby says:

    Thanks Vishal, Your way to get the cat id is the only one that worked for me in the head.phtml file for Magento 1.7. It is a little frustrating to have such a hard time getting something like this to work in your template.

  10. […] Magento : Get Current Category – Category Id June 2010 1 comment […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s