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.


16 thoughts on “Magento – Get the Current Category”

  1. 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

  2. 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

    {syntaxhighlighter brush: php}Mage::registry(‘current_category’)->getTitle();{/syntaxhighlighter}

    but this doesn’t work

  3. Magento

    $_helper = $this->helper(‘catalog/output’);


    $products = $_category_detail->getProductCollection()->joinField(‘inventory_in_stock’, ‘cataloginventory_stock_item’, ‘is_in_stock’, ‘product_id=entity_id’,’is_in_stock > 0′, ‘left’)->setOrder(‘inventory_in_stock’,’asc’)->addAttributeToFilter(‘visibility’, 4);

    $products->getSelect()->order(new Zend_Db_Expr(‘RAND()’))->limit(4 );

    its working fine on localhost but showing error on live site.

    error: call to function getProductCollection() on a non-object.

    so what will the problem??

    if i used $_category_detail = Mage::getModel(‘catalog/category’); instead of


    then its working fine but my output going to wrong ….

    so $_category_detail = Mage::getModel(‘catalog/category’); have any parameter where i can load current category of product on product page or(realated page)

  4. Hello,

    is there an alternative way to get the current category? In my case the result of Mage::registry(‘current_category’) is empty!

Leave a Reply

Your email address will not be published. Required fields are marked *