What a Body

In 2.7 WordPress added threaded comments with a neat little function that would output the comment code complete with loads of standard CSS classes, we also have post_class which outputs standard classes for post. In 2.8 the class-fest goes further with a new function: body_class.

Body class goes in the body tag of each web page and outputs classes depending on the type of page that is being viewed. At the moment it outputs the following classes (it should be obvious what each is for)

rtl

home

blog

archive

date

date-paged-#

search

search-paged-#

paged

paged-#

attachment

error404

single

single-paged-#

page-paged-#

postid-#

attachmentid-#

attachment-{mime type}

(if date archive) date-paged-#

(if author archive) author

(if author archive) author-paged-#

(if author archive) author-{name}

(if category archive) category

(if category archive) category-paged-#

(if category archive) category-{slug}

(if tag archive) tag

(if tag archive) tag-paged-#

(if tag archive) tag-{slug}

page-parent

page-child

parent-pageid-#

page-template

page-template-{name}

search-results

search-no-results

logged-in

I guess there is still some cleaning up to do on this as there are a few missing options, but it looks to be comprehensive and should help with further standardising themes.

Despite the obvious value of this though something just doesn’t sit right with me about creating core functions to output classes. I can’t put my finger on why I don’t like it at the moment, but as the concept is clearly here to stay I guess it doesn’t really matter. Enjoy the new classes.