Magento: Get Current Category or Get Current Category on product listing

There are two ways to get current category in Magento:

1) When you don’t have access to $this, you can use Magento registry:

$categoryId = Mage::registry(‘current_category’)->getId();

2) When you have access to $this, you can use product list block:

$this->getLayout()->getBlock(‘product_list’)->getCategoryId(); // get product list block object to get product listing of current category.

Leave a Reply