Jump to content

Adding A Class To the Body


Robo_1

Recommended Posts

I've spent the past few hours banging my head against this problem, and I'm wondering if anyone can help.

Basically, what I'm looking to do is give the body element a class of the same name as the category it's associated with.

So if I have a shop which sells widgets, what I'm looking to do is give the category and product pages associated with blue widgets, a blue-widget class on the body, so that I can add custom styles to match that category on some of the template elements.

I've tried doing this: <body class="{$category.cat_name}"> but what's suitable as a title isn't always suitable for a class, and as soon as I had titles of more than one word, everything quickly fell apart. I've also considered subverting the meta-keywords option to get the word I need, but obviously that would be a rather messy fix.

So if anyone can think of how I could do this, I'd be most appreciative.

Thanks. :)

Link to comment
Share on other sites

  • 1 month later...

Did you ever get anywhere with this? I'm trying to figure out the same thing right now. As far as I know the code you posted won't do anything because you need to pair the call for the Category Name to a database call that's usually in an inc.php file. Not that it's helped me solve the problem yet either.

Did you find anything else out?

Sorry I can't be of more help to you.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...