You are herecheck whether on product page or category - Magento

check whether on product page or category - Magento


By admin - Posted on 11 May 2011

The easy and fastest way to check whether you are on product page or category page is to check the registry to see if we have a single product that we are looking at:

<?php 

if(Mage::registry('current_product')) {
  
  echo "You are on product page" ;

} else {
  echo "You are outside the product page";
}

?>

For any Category / Product page, you are getting the ID from

<?php
Mage::app()->getRequest()->getParam('id');
$product = Mage::getModel('catalog/product')
               ->load(Mage::app()->getRequest()->getParam('id'));
if(!empty($product->getSku())) {
    echo 'Inside the Product page definitely';
}

This method works, but less faster than the above one. 


You can also check the page type (category or product) by reading the controller name:
Mage::app()->getRequest()->getControllerName(); 
if($this->getRequest()->getControllerName()=='product') {
echo "You are on product page" ; 
}
if($this->getRequest()->getControllerName()=='category'){
 echo "You are on category page";
}

 ?>