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.

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s