function k2_body_class($print = true) { global $wp_query, $current_user, $blog_id; $c = array('wordpress', 'k2'); // Applies the time- and date-based classes (below) to BODY element k2_date_classes(time(), $c); // Generic semantic classes for what type of content is displayed is_front_page() ? $c[] = 'home' : null; is_home() ? $c[] = 'blog' : null; is_archive() ? $c[] = 'archive' : null; is_date() ? $c[] = 'date' : null; is_search() ? $c[] = 'search' : null; is_paged() ? $c[] = 'paged' : null; is_attachment() ? $c[] = 'attachment' : null; get_option('unwakeable_rollingarchives') == '1' ? $c[] = 'rollingarchives' : null; get_option('unwakeable_animations') == '1' ? $c[] = 'animations' : null; is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character if (is_attachment()) { $postID = $wp_query->post->ID; the_post(); // Adds 'single' class and class with the post ID $c[] = 'postid-' . $postID . ' s-slug-' . $wp_query->post->post_name; // Adds classes for the month, day, and hour when the post was published if (isset($wp_query->post->post_date)) { k2_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-'); } $the_mime = get_post_mime_type(); $boring_stuff = array('application/', 'image/', 'text/', 'audio/', 'video/', 'music/'); $c[] = 'attachment-' . str_replace($boring_stuff, '', $the_mime); // Adds author class for the post author $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author())); rewind_posts(); } elseif (is_single()) { $postID = $wp_query->post->ID; the_post(); // Adds 'single' class and class with the post ID $c[] = 'single postid-' . $postID . ' s-slug-' . $wp_query->post->post_name; // Adds classes for the month, day, and hour when the post was published if (isset($wp_query->post->post_date)) { k2_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-'); } // Categories foreach ((array) get_the_category() as $cat) { if (empty($cat->slug)) { continue; } $c[] = 's-category-' . $cat->slug; } // Tags foreach ((array) get_the_tags() as $tag) { if (empty($tag->slug)) { continue; } $c[] = 's-tag-' . $tag->slug; } // Adds author class for the post author $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author())); if (get_post_custom_values('sidebarless')) { $c[] = 'sidebars-none'; } if (get_post_custom_values('hidesidebar1')) { $c[] = 'hidesidebar-1'; } if (get_post_custom_values('hidesidebar2')) { $c[] = 'hidesidebar-2'; } rewind_posts(); } else { if (is_author()) { $author = $wp_query->get_queried_object(); $c[] = 'author'; $c[] = 'author-' . $author->user_nicename; } else { if (is_category()) { $cat = $wp_query->get_queried_object(); $c[] = 'category'; $c[] = 'category-' . $cat->category_nicename; } else { if (is_tag()) { $tag = $wp_query->get_queried_object(); $c[] = 'tag'; $c[] = 'tag-' . $tag->slug; } else { if (is_page()) { $pageID = $wp_query->post->ID; $page_children = wp_list_pages("child_of={$pageID}&echo=0"); the_post(); $c[] = 'page pageid-' . $pageID; $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author())); $c[] = 'page-slug-' . $wp_query->post->post_name; // Checks to see if the page has children and/or is a child page; props to Adam if ($page_children != '') { $c[] = 'page-parent'; } if ($wp_query->post->post_parent) { $c[] = 'page-child parent-pageid-' . $wp_query->post->post_parent; } if (get_post_custom_values('sidebarless')) { $c[] = 'sidebars-none'; } if (get_post_custom_values('hidesidebar1')) { $c[] = 'hidesidebar-1'; } if (get_post_custom_values('hidesidebar2')) { $c[] = 'hidesidebar-2'; } rewind_posts(); } } } } } // Paged classes; for 'page X' classes of index, single, etc. $page = intval($wp_query->get('paged')); if (is_paged() && $page > 1) { $c[] = 'paged-' . $page . ''; if (is_single()) { $c[] = 'single-paged-' . $page . ''; } else { if (is_page()) { $c[] = 'page-paged-' . $page . ''; } else { if (is_category()) { $c[] = 'category-paged-' . $page . ''; } else { if (function_exists('is_tag') and is_tag()) { $c[] = 'tag-paged-' . $page . ''; } else { if (is_date()) { $c[] = 'date-paged-' . $page . ''; } else { if (is_author()) { $c[] = 'author-paged-' . $page . ''; } else { if (is_search()) { $c[] = 'search-paged-' . $page . ''; } } } } } } } } // For when a visitor is logged in while browsing if ($current_user->ID) { $c[] = 'loggedin'; } // Sidebar layout settings switch (get_option('unwakeable_columns')) { case '1': $c[] = 'columns-one'; break; default: case '2': $c[] = 'columns-two'; break; case 'dynamic': case '3': $c[] = 'columns-three'; break; } // Language settings $locale = get_locale(); if (empty($locale)) { $locale = 'en'; } else { $lang_array = split('_', $locale); $locale = $lang_array[0]; } $c[] = 'lang-' . $locale; // For WPMU. Set a class for the blog ID if (isset($blog_id)) { $c[] = 'wpmu-' . $blog_id; } // Browser/Platform Specific Classes $c = array_merge($c, k2_browser_classes()); // Separates classes with a single space, collates classes for BODY $c = esc_attr(join(' ', apply_filters('body_class', $c))); // And tada! return $print ? print $c : $c; }
function k2_body_class_filter($classes) { global $wp_query, $blog_id; $classes[] = 'wordpress k2'; /* Detect whether the sidebars are in use and add appropriate classes */ if (is_active_sidebar('widgets-sidebar-1') && is_active_sidebar('widgets-sidebar-2')) { $classes[] = 'columns-three'; } else { if (is_active_sidebar('widgets-sidebar-1')) { $classes[] = 'columns-two widgets-sidebar-1'; } else { if (is_active_sidebar('widgets-sidebar-2')) { $classes[] = 'columns-two widgets-sidebar-2'; } else { $classes[] = 'columns-one'; } } } switch (get_option('k2usestyle')) { case 0: // No CSS $classes[] = 'nok2css'; break; case 1: // Sidebars Left $classes[] = 'sidebarsleft'; break; case 2: // Sidebars Right $classes[] = 'sidebarsright'; break; case 3: // Flanking Sidebars $classes[] = 'flankingsidebars'; break; } // If animations are turned on if ('1' == get_option('k2animations')) { $classes[] = 'animations'; } // Only on single posts and static pages if (is_single() or is_page()) { // Add 'author-XXXX' class $author = get_userdata($wp_query->post->post_author); $classes[] = 'author-' . sanitize_html_class($author->user_nicename, $author->ID); // If the post or page has a relevant custom field set if (get_post_custom_values('sidebarless')) { $classes[] = 'sidebars-none'; } if (get_post_custom_values('hidesidebar1')) { $classes[] = 'hidewidgets-sidebar-1'; } if (get_post_custom_values('hidesidebar2')) { $classes[] = 'hidewidgets-sidebar-2'; } // Add 'slug-XXXX' for the post or page slug -- CONSIDER REMOVING; WHAT WORTH DOES IT HAVE OVER 'postid-X'? $classes[] = 'slug-' . $wp_query->post->post_name; // Only for posts... if (is_single()) { // Adds classes for the month, day, and hour when the post was published if (isset($wp_query->post->post_date)) { k2_date_classes(mysql2date('U', $wp_query->post->post_date), $classes, 's-'); } // Add 'category-XXXX' for each relevant category foreach ((array) get_the_category($wp_query->post->ID) as $cat) { if (empty($cat->slug)) { continue; } $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID); } // Add 'tag-XXXX' for each relevant tag foreach ((array) get_the_tags($wp_query->post->ID) as $tag) { if (empty($tag->slug)) { continue; } $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id); } } } // Language settings $locale = get_locale(); if (empty($locale)) { $locale = 'en'; } else { $lang_array = explode('_', $locale); $locale = $lang_array[0]; } $classes[] = 'lang-' . $locale; // For WPMU. Set a class for the blog ID if (isset($blog_id)) { $classes[] = 'wpmu-' . $blog_id; } // Applies the time- and date-based classes (below) to BODY element k2_date_classes(time(), $classes); $classes = array_merge($classes, k2_browser_classes()); return $classes; }