I'm looking for a way to add a css class to my pages using the standard $vars[] method when the page is generated by a taxonomy/term path as opposed to by a view or anything else (like a standard page object). Is there a way I can determine this with php I can insert in my template.php file?

For example, I am looking to add:


...

when the page is generated by taxonomy/term and


...

otherwise.

Thanks in advance!

Comments

hawkeye217’s picture

This should have said:

<body class="taxonomy-generated-page">
...
</body>

when the page is generated by taxonomy/term and

<body class="standard-generated-page">
...
</body>

otherwise.

smokingtrucks’s picture

1. Use the arg function to check the path

if (arg(0) == 'taxonomy' && arg(1) == 'term' ) {
  $vars['body_class'] = 'taxonomy';
} else {
  $vars['body_class'] = 'standard';
}

2. Modify your page template (page.tpl.php) to add the body class variable

<body class="<?php print $body_class; ?>">
hawkeye217’s picture

Works great.

Would it apply in the same manner for url aliases?

I'm hunting around for some docs on the arg function...