Normally if I wanted to add a custom post class I would use the post_class
filter.
However, when using a custom loop the post_class
filter is not accessible.
I am trying to apply classes that will place posts into columns depending on the count. Here is the example code I would use when not using a custom loop;
//Add Post Class Filter
add_filter('post_class', 'sk_post_class');
function sk_post_class($classes) {
global $loop_counter;
$classes[] = 'one-third';
if (($loop_counter + 3) % 3 == 0) {
$classes[] .= 'first';
}
$loop_counter++;
return $classes;
}
Each post in my custom loop is wrapped with <div class = "answers"></div>
. I am thinking that I need to be able to modify the code above to add classes to <div class = "answers">
based on the loop counter.
Can anyone point me in the right direction to how I might be able to achieve this?
post_class
filter works fine in custom loops if you've used thepost_class
function correctly. edit your question to add your custom loop code with thepost_class
function.