I am trying to set up a featured content section of my blog. This will contain two sticky posts.
I have a custom loop which will only display the two sticky posts, in the loop I then get a content-featured.php
template which has the structure of the sticky posts.
In the main post div I use post_class()
. I know I can pass a value like post_class('featured')
but I would like to have a different class name for each sticky post, i.e. featured-0
, featured-1
.
I have attempted to create a function in functions.php
, but as I know very little about PHP, I am struggling to get it to work. Here's what I have:
//add classes to sticky posts
function gwad_sticky_classes( $classes, $class ) {
$sticky = get_option( 'sticky_posts' );
if ( $sticky ) {
$query = new WP_Query( $sticky );
$sticky[0] ='featured-0';
$sticky[1] = 'featured-1';
}
return $classes;
}
add_filter( 'post_class', 'gwad_sticky_classes', 10, 2 );
As you can see, I don't have a clue what I'm doing, any help would be greatly appreciated.