Basically, I want to give my articles and blog entries a different class on the body so I can style them independently.

I am given to understand that the best way to do this is with creating custom tpl files

I'm working in a custom built theme that is pretty much running just on a page.tpl.php and a stylesheet.

How would I do this easily in Drupal 7? I tried this method for drupal 6 but it didn't seem to work.

1 Answer 1


This should by there by default.

For example, the body classes on my test site look like this for a simplenews node:

<body class="html not-front logged-in one-sidebar sidebar-first page-node page-node- page-node-90 node-type-simplenews toolbar toolbar-drawer i18n-en" >

As you can see, there is node-type-simplenews, among many other things.

Those classes are defined in template_preprocess_html() and are using in html.tpl.php (not page.tpl.php, unless you've overriden that. If so, you need to duplicate the logic in that function for your page.tpl.php.

  • Wow you're right. I thought I had checked that, but I had not realized that chrome developer tools summarizes the inheritence list at the bottom.. i thought it was showing me everything.
    – Damon
    Mar 2, 2012 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.