The post_class
filter is your friend. Just combine it with get_post_meta()
.
function wpse80098_filter_post_class( $classes ) {
global $post;
if ( 'yes' == get_post_meta( $post->ID, '_jsFeaturedPost', true ) ) {
$classes[] = 'my-custom-css-class';
}
return $classes;
}
add_filter( 'post_class', 'wpse80098_filter_post_class' );
Just replace my-custom-css-class
with whatever class you want to apply to the post container in question.
As noted in the comments, this implementation relies on the post_class()
template tag being called properly in the post container, e.g.:
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
Edit
Re: this question in the comments:
Is there a way I can dynamically prepend an a tag to the posts with the featured class?
The easiest method is probably to filter the_content
:
function wpse80098_filter_the_content( $content ) {
global $post;
if ( 'yes' == get_post_meta( $post->ID, '_jsFeaturedPost', true ) ) {
return '<a href="http://example.com">' . $content . '</a>';
}
return $classes;
}
add_filter( 'the_content', 'wpse80098_filter_the_content', 99 );
Add a very high priority number, so that this filter gets applied last.