Leveraging CSS to change your theme

Overview

Style.css

No Styles

WordPress class functions

Where to put them

If your theme does not have these functions built in, not to worry.

Body Class

The body tag is typically located in the header.php file of your theme.

<body <?php body_class(); ?>>

Post Class

Post class goes wherever you have posts, could be index.php, archive.php, search.php, etc.

<div <?php post_class(); ?>>

Comment Class

Comment classes are baked into the wp_list_comments function, or can be manually placed in a custom callback.

<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">

Comment Class

<li class="comment even thread-even depth-1 bypostauthor" id="comment-63">

Translation

Comment Class

<li class="comment even thread-even depth-1 bypostauthor" id="comment-63">

How To Target

.bypostauthor { background: #000; color: #fff; /* sets the background color to black, font color white */ }
.even { background: #ccc; /* light gray color */ }
#comment-63 { font-weight: bold; }

Classes vs. IDs

Comment Class

Sample CSS

.bypostauthor { background: #000; color: #fff; }
.even { background: #ccc; }
#comment-63 { font-weight: bold; }

Sample

First comment is even
Comment author
Third comment is even
Fourth comment is odd

Post Class

<div id="post-1" class="post-1 post type-post sticky hentry category-uncategorized">

Translation

Post Class

<div id="post-1" class="post-1 post type-post sticky hentry category-uncategorized">

Example

Styling the "sticky" post to have an icon added to it.

.sticky { background-image: url('images/yield.png'); }

Post Class Sample

Source: WooThemes Ultimate Icon Set

Body Class

<body class="archive category category-wizards">

Translation

Body Class Sample

Body Class

<body class="archive category category-wizards">

Example

Styling the Wizards category archive with a custom background, as well as altered navigation menu colors.

Body Class Sample

Body Class

<body class="archive category category-wizards">

Example

Styling the Wizards category archive with a custom background, as well as altered navigation menu colors.

body.category-wizards { background-image: url('images/wizards-logo.png'); background-repeat: no-repeat; }

.category-wizards #access { background: #005183; } /* Navigation Menu Background */

.category-wizards #branding img { border-bottom:1px solid #005183; border-top:4px solid #005183; /* Sets the border colors of the header image */ }

Applying the Changes

Two Options

Sample Child Theme Structure

/*
	Theme Name: Sample Child Theme
	Theme URL: http://www.example.com
	Description: This is a sample for my WordPress DC presentation.
	Author: Leland Fiegel
	Author URI: http://leland.info
	Version: 1.0
	Template: twentyten
*/

@import url("../twentyten/style.css");

/* Changes Go Here */

Further Resources

Questions?