How to get the current category name from product view and list

Posted by Labels: at

Use the php code below to get current category name, sadly it only works on certain template files,
namely the product view and product list.

Product view template path:
app/design/frontend/package_name/theme_name/template/catalog/product/view.phtml 

Product list template path:
app/design/frontend/package_name/theme_name/template/catalog/product/list.phtml 


<?php
     $current_category = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getName();
     //check for      if( $current_category == 'Shoe-wear') {         echo "<style> body { background-image: #00 }</style>";     }
?>


But any other file within the Catalog/ template folder should also be able to use this code,

app/design/frontend/package_name/theme_name/template/catalog/

I usually use this approach if i want to change the background of my product view page, for that particular product, just to add some fun customisation for my shoppers. I hope this article was helpful to you, please leave your question/s on the comments section below and I will do my best to answer back.

Post a Comment

Back to Top