2998 readersIntroduced in WordPress 2.8, body_class() is a very useful function when it comes to styling themes. In this recipe, I'll show you how you can add post name to the function for an even easier styling.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!WordPress hack:
9721 readers
PHP
function mfields_add_more_to_post_class( $classes ) {
global $post;
if ( ( is_archive() || is_home() ) && false !== strpos( $post->post_content, '' ) && ! in_array( 'more', $classes ) ) {
$classes[] = 'more';
}
return $classes;
}
add_filter( 'post_class',
7328 readers
PHP
add_filter('body_class','add_body_classes');
function add_body_classes($classes) {
$classes[] = 'my-class-one';
$classes[] = 'my-class-two';
$classes[] = 'my-class-three';
return $classes;
}
PHP
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon | Delicious | Tweet It | Digg This | DesignBump-It |
3803 readers
PHP
add_filter('body_class','body_class_section');
function body_class_section($classes) {
global $wpdb, $post;
if (is_page()) {
if ($post->post_parent) {
$parent = end(get_post_ancestors($current_page_id));
} else {
3419 readersThe default output for WordPress’ post_class template tag includes class names for just about every type of page view imaginable:
page-parent
search-results
logged-in
author
paged
Plus just about everything else except for category ID information. It gives some good category-specific class names, but nothing to represent the category ID. For example, including the post_class function like this in your markup:
<div <?php
-
7416 readersToday I would like to show you, how to assign CSS classes to custom post types for styling your website. Basically we just extend the function body_class() of WordPress with our own post types, so that we can address them to style our design accordingly.The same I had already explained in detail in another
2692 readersWe covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably
7130 readers
PHP
add_filter( 'getarchives_where' , 'ucc_getarchives_where_filter' , 10 , 2 );
function ucc_getarchives_where_filter( $where , $r ) {
$args = array( 'public' => true , '_builtin' => false );
$output = 'names'; $operator = 'and';
$post_types = get_post_types( $args , $output , $operator );
$post_types = array_merge( $post_types , array( 'post','CUSTOM_POST_TYPE_NAME' ) );
$post_types = "'" . implode( "' , '" , $post_types
4208 readersBy default, when the blog admin left a comment on his blog, WordPress use the name in the comment css class. This is useful for styling, but it will also let people know about your admin login name. If you want to hide this info, read this recipe.Looking for WordPress hosting? Try WP Web Host.
6041 readers
PHP
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var) {
return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
}
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon | Delicious | Tweet It | Digg This | DesignBump-It | DesignPoke-it