Determine Category and Product page in Magento

Some times in Magento we need to put some snippets only on the Category(Product Listing) or Product Details page.

The following code helps to determine whether it is Category page or not?

<?php
if(Mage::registry('current_category')) {
    //Place your content/snippet here
}
?>

 

The following code helps to determine whether it is Product Details page or not?

 

<?php
if(Mage::registry('current_product')) {
    //Place your content/snippet here
}
?>

We could use this code anywhere in modules or in ,phtml files placed under ‘app/design/frontend/[package]/[theme]/ template/’

Cheers!

Leave a Reply

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