Jump to content

[SOLVED] Category names as classes in header.tpl


Recommended Posts

Hi,

 

I am using categories that have sub categories such as:

 

1) Womens

1a) Dresses

1b) Hats

 

2) Mens

2a) Trousers

2b) Shoes

 

And so on...

 

Now, I want to add the root class to the body eg. '<body class="womens">' but ideally I also want to add the current category too: eg. '<body class="womens hats">'.

 

All of the above is so that I can style women, men etc pages with unique styles. In places I also want to style things uniquely for sub categories too.

 

I have seen that you can use the following:

 

{$category->name} - but this only shows current category

{$id_category_parent} - but this is just an id, cannot see a way of translating this into a name

 

In essence, I'm looking at something similar to a breadcrumb but written to a class. I have even looked at breadcrumb.tpl but with limited success.

 

I have spent many hours looking for a solution to this problem but have found no real solution, hope someone can help? I'm using Presta ver. 1.5.5

 

Thanks,

 

Adam.

 

P.S. I'm also try to get the friendly URL within CMS pages to display, $meta_title displays the normal name but I do not want this.

Edited by mediabunker (see edit history)
Link to comment
Share on other sites

Here's what I'd do.

I would create a module that hook to the header. From this header hook, I would grab the category id with Tools::getValue('id_category')

 

Then, instantiate a new category object. At this point you can assing the link_rewrite value to a smarty variable, so that you can add the current category's hyphened version of the name as a class.

 

Then, with the same instance use $categoryInstance->getParentsCategories(); to get all its parents. Iterate throught the parents and get the one with id_parent = 0 or 1, or in any case the chils of the root category's id. Grab it's link_rewrite, which should already be there, and assign it as a smarty variable as well :)

Link to comment
Share on other sites

  • 8 months later...
×
×
  • Create New...