Plugin / Ambrosite Body Class Enhanced

J. Michael Ambrosio

Description

Description

When activated, this plugin causes the body_class template tag to output five additional classes.

On single posts (is_single) :
postname-[permalink slug]
single-[category slug]
parent-[parent category slug] (all parent and grandparent categories in a hierarchy of any depth)

On pages (is_page) :
pagename-[permalink slug]

On category archives (is_archive and is_category) :
parent-category-[parent category slug] (all parent and grandparent categories in a hierarchy of any depth)

Custom Taxonomies

As of version 1.3, the plugin now supports custom hierarchical taxonomies. The new body classes take the following form:

On single posts (is_single) :
single-[taxonomy]-[term slug]
parent-[taxonomy]-[parent term slug] (all parent and grandparent terms in a hierarchy of any depth)

On taxonomy archives (is_archive and is_tax) :
parent-term-[parent term slug] (all parent and grandparent terms in a hierarchy of any depth)

For single posts, the taxonomy name is included in the class name, because I felt it was important to be able to distinguish between taxonomies in cases where a post is assigned to more than one custom taxonomy, and when the same term might appear in two or more taxonomies. For example, suppose you had a real estate site with property listings in New York City, and you had two custom taxonomies defined: City and State. Then the classes would look like this:

single-city-new-york single-state-new-york

Multisite Support

As of version 1.3, the plugin now supports multisite installations. If a multisite install is detected, the plugin will output the follow additional body class on every page of the site:

site-[site ID]

Examples

If you have a post titled “Top 10 Decorating Ideas”, in category “Christmas”, with a parent category of “Holidays” and a grandparent category of “Calendar”, the additional body classes will be as follows:

postname-top-10-decorating-ideas single-christmas parent-holidays parent-calendar

Why is this useful? Because it enables you to style individual posts and pages, as well as entire categories of posts, using only CSS, without having to edit the template files or create new templates.

Continuing the above example, if I wanted to give all of the posts in the Christmas category a green heading (to give them some extra holiday cheer), I could use a CSS selector like this:

body.single-christmas h1 {
    color: green;
}

Going further, suppose I want to attach a background image of a Christmas tree ONLY to the “Top 10 Decorating Ideas” post:

body.postname-top-10-decorating-ideas div.post {
    background: url('images/xmas_tree.gif') no-repeat left top;
}

What if I want all posts categorized under Holidays (Christmas, Thanksgiving, Easter, whatever) to have a sidebar with a gold border?

body.parent-holidays div#sidebar,  /* all posts assigned to a subcategory of Holidays */
body.single-holidays div#sidebar { /* any posts assigned directly to the Holidays category */
    border: solid 2px gold;
}

These are just a few examples. If you are experienced in writing CSS selectors, you will find many more uses for the new body classes. For further discussion, check this support forum thread: https://wordpress.org/support/topic/393942

Ratings

5
4 reviews

Rating breakdown

Details Information

Version

1.3

First Released

20 Apr, 2010

Total Downloads

6,465

Wordpress Version

2.8 or higher

Tested up to:

3.2.1

Require PHP Version:

-

Tags

Contributors

Languages

The plugin hasn't been transalated in any language other than English.

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.