How do I create a sticky sidebar?

I did not really understand your question, but try this (using bootstrap v3): <div class=”clearfix”> <?php $a = 0; $classes = array(‘post-1′,’post-2′,’post-3’); query_posts(‘category_name=Menucard’); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class=”<?php echo $classes[$a]; ?> col-4 post move pull-left”> <?php //echo post here the_content(); ?> </div> <!– close … Read more

Adding post_class into functions.php query

post_class() will echo the class in the format class=”postclassA postclassB” get_post_class() will return an array of all registred classes To use get_post_class() inside sprintf(), you have to return the array as a string. For this purpose you can use the join() function. Example $classes = join(‘ ‘, get_post_class()) $sidebar = sprintf(‘<div id=”post-%s” class=”%s”>%s</div>’, get_the_ID(), $classes, … Read more

post_class output in wrong area?

post_class() echos so that’s you’re problem. From the codex: If you would prefer to have the post classes returned instead of echoed, you would want to use get_post_class(). So just do this: $the_post_classes = get_post_class( ‘clearfix’ ); $the_post_class_string = ”; foreach( $the_post_classes as $post_class ) { $the_post_class_string .= $post_class . ‘ ‘; } $defaults = … Read more

How to use post_class function?

Use the post_class filter to test multiple conditions: function wpa_post_class( $classes ) { global $post; if( ! has_post_thumbnail() ) $classes[] = “no-image”; if( get_the_content() == “” ) $classes[] = “no-content”; return $classes; } add_filter( ‘post_class’, ‘wpa_post_class’ ); Then your html will just be: <li id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>

Alternate post_class on each post

You should add the following code in functions.php: add_filter ( ‘post_class’ , ‘my_post_class’ ); global $current_class; $current_class=”odd”; function my_post_class ( $classes ) { global $current_class; $classes[] = $current_class; $current_class = ($current_class == ‘odd’) ? ‘even’ : ‘odd’; return $classes; } This ensures that all the odd posts on the page will have the class ‘odd’ … Read more

Remove and add class with body_class() function

The my_custom_class() function is using the class name my-custom-class, but the CSS is targeting the class my_custom_class. These two strings should be exactly the same: .my-custom-class { margin-top: 350px !important; } Also, it would be a little cleaner to handle all of the body_class stuff in a single callback function: add_action( ‘body_class’, ‘my_custom_class’); function my_custom_class( … Read more

Add a different class name to each sticky post?

Here’s a solution that adds additional sticky classes, one for the post ID and one for the sticky post counter. /** * Adds .featured-{$post_id} and .featured-{$sticky_counter} * class names to sticky posts. * * @param array $classes An array of post classes. * @param array $class An array of additional classes added to the post. … Read more