RawDev.net - Just another Zabreznik.si Sites site
Home - Mail - About

Magento Category Style

Thursday, February 19th, 2009 by

Its frequent that a webpage needs styles specific to categories, like one background for Store, another for Company info etc… But Magento fails in that area unless you want to make specific designs for each section you are out of luck.

CSS might be the ansver trough. The only thing missing is a class that each section has.
addBodyClass(‘category-’.Mage::getBlockSingleton(‘catalog/navigation’)
->getCurrentCategory()
->getParentCategory()
->getUrlKey()
);
?>
This piece of code adds the urlkey of the current categories parent category inside body’s class tag. And the class added is the same that is present on the parent page of the category. How cool is that :D

For pages with multiple level childs, it is also possible to loop that untill you get to the top parent.

This entry was posted on Thursday, February 19th, 2009 at 5:22 pm under Magento.
You can follow any responses to this entry through the RSS 2.0 feed. 2 Responses.
You can leave a response, or trackback from your own site.
Alex
July 15th, 2009 at 6:57 am

Unfortunately you did not write WHERE this piece of code has to be put in?


Hekos
July 18th, 2009 at 10:17 am

this was supposed to go anywhere before the body class function was called.

this code is obsolete on newer versions… since the category is already there.. but can still be used if you want other classes to be placed dynamically..


« »