harry07
Member
Posted 4 years ago #
Hello. I'm trying to make a new theme but I'm stuck. I just want to ask how you can assign a unique class for every single post that appears on the front page without using the the_ID template tag because I want the classes to be static. Help?
Thanks in advance!
ionfish
Member
Posted 4 years ago #
Should be pretty simple to do this by writing a function hooking into the post_class filter, e.g.
function add_unique_post_class($classes, $class, $post_id) {
$classes[] = "unique_class_$post_id";
return $classes;
}
add_filter('post_class', 'add_unique_post_class', 10, 3);
...without using the the_ID template tag because I want the classes to be static...
I don't get it. Post id's are static. They don't change. So why not use the post-id thing as an id (instead of as a class, since an ID makes more sense here).