And if you are not using WP 2.8 you can use my old functions. Stick
these in your themes functions.php. The call then from within your
body element. And yes there are two functions. One for the body ID and
one for the body class.
/////////////////////////////////////////////////////////
// Add a unique id attribute to the body tag of an HTML
// page
/////////////////////////////////////////////////////////
function id_the_body() {
global $post, $wp_query, $wpdb;
$post = $wp_query->post;
if ($post->post_type == 'page') $body_id = 'page-' . $post->ID;
if ($post->post_type == 'post') $body_id = 'post-' . $post->ID;
if ( is_front_page() ) $body_id = 'home';
if ( is_home() ) $body_id = 'blog';
if ( is_category() ) $body_id = 'category-' . get_query_var('cat');
if ( is_tag() ) $body_id = 'tag-' . get_query_var('tag');
if ( is_author() ) $body_id = 'author-' . get_query_var('author');
if ( is_date() ) $body_id = 'date-archive';
if (is_search()) $body_id = 'search-archive';
if (is_404()) $body_id = '404-error';
if ($body_id) echo "id=\"$body_id\"";
}
/////////////////////////////////////////////////////////
// Add special class names for the parents of the page
// i.e. childof-112
/////////////////////////////////////////////////////////
function class_the_body($more_classes='') {
global $post, $wp_query, $wpdb;
$post = $wp_query->post;
if ($post->ancestors) {
// reverse the order of the array elements b/c we want the
immediate
parent to be last in the class list
$parent_array = array_reverse($post->ancestors);
foreach ($parent_array as $key => $parent_id) {
$parent_id_string = $parent_id_string . ' childof-' .
$parent_id;
}
}
if ($post->post_type == 'page') $type = 'page';
if ($post->post_type == 'post') $type = 'post';
// these 2 are not needed since we id the body with home
//if (is_home()) $type = 'home';
//if (is_front_page()) $type = 'front';
if (is_category()) $type = 'archive category-archive';
if (is_tag()) $type = 'archive tag-archive';
if (is_author()) $type = 'archive author-archive';
// again, these 3 are not needed since we id the body with these
if (is_date()) $type = 'archive date-archive';
if (is_search()) $type = 'archive search-archive';
if (is_404()) $type = '404-error';
// need a lot of trimming b/c any combination of these could be blank
$classes = trim($parent_id_string . ' ' . $more_classes);
if ($type) $classes = $type . ' ' . $classes;
$classes = trim($classes);
if ($classes) echo "class=\"$classes\"";
}
On Sep 22, 2009, at 7:50 PM, Pat Ramsey wrote:
> This is what will work best, assuming you're on WP 2.8 or newer.
> <body <?php body_class(); ?>>
>
> Then you get nice classes on your body tag which let you style
> things based on the page being viewed.
>
> Cheers!
>
> Pat
>
>
> [email protected]
> 512.736.6227
> @pat_ramsey
> http://slash25.com
>
> Code that works,... beautifully
> -- sent from my iPhone --
>
> On Sep 22, 2009, at 16:09, Paul <[email protected]> wrote:
>
>> <body <?php body_class(); ?>>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
Our Web site: http://www.RefreshAustin.org/
You received this message because you are subscribed to the Google Groups
"Refresh Austin" group.
[ Posting ]
To post to this group, send email to [email protected]
Job-related postings should follow http://tr.im/refreshaustinjobspolicy
We do not accept job posts from recruiters.
[ Unsubscribe ]
To unsubscribe from this group, send email to
[email protected]
[ More Info ]
For more options, visit this group at
http://groups.google.com/group/Refresh-Austin
-~----------~----~----~----~------~----~------~--~---