Title: css with body class
Last modified: August 20, 2016

---

# css with body class

 *  [roclimb](https://wordpress.org/support/users/roclimb/)
 * (@roclimb)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/css-with-body-class/)
 * Hi I added: <body <?php body_class(‘myclass’); ?>> and added .myclass #divname
   to my style.css and it works great and changes css for a page called state-page.
   My question is I have about 45 pages with the same “state-page” template I want
   the .myclass added to. Is there a way to declare this page as a catagory or something
   similar so WordPress will know that I want .myclass added through body_class 
   to those pages?
 * I would like to acheive this alternate css through the body_class as I have other
   pages with different css and this is the best solution for my needs.
 * thanks

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/css-with-body-class/#post-2670672)
 * > pages with the same “state-page” template
 * the `body_class()` function will automatically add a page template specific class;
 * [http://codex.wordpress.org/Function_Reference/body_class](http://codex.wordpress.org/Function_Reference/body_class)
 * `.page-template-templatefilename-php`
 *  Thread Starter [roclimb](https://wordpress.org/support/users/roclimb/)
 * (@roclimb)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/css-with-body-class/#post-2670736)
 * As always thanks again for the reply. I think I worded my question poorly. what
   I wanted to ask is:
 *  I have a template called area-page that is linked to style.css and will have
   about 50 pages looking like that template, then
 * I will have another 50 pages coming from area-page template but changed the css
   slightly through <?php body_class(‘myclass’); ?>>. these pages I want to all 
   have the class .myclass added to so it looks a little different from the regular
   area-template. So I want a simple way to add the .myclass to do this. I did it
   for one page and it looks great but I have 49 more to add it to and dont want
   to have to add the page name 49 times.
 * Is there a way to add .myclass to a set of these 49 pages?
 *  Thread Starter [roclimb](https://wordpress.org/support/users/roclimb/)
 * (@roclimb)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/css-with-body-class/#post-2670938)
 * I think I figured out what I need. I will add the category of the page to be 
   detected and make a conditional statement to detect the category and then add
   the class depending on category. this way I can have a ton of pages under one
   category and not have to add the class to individual names.
 * Cheers
    Rob

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘css with body class’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [roclimb](https://wordpress.org/support/users/roclimb/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/css-with-body-class/#post-2670938)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
