Display Posts adds a class of .listing-item
to each post in the listing. You can customize the classes using the display_posts_shortcode_post_class
filter.
The following code adds a class to each listing item of post-{id}
, so if the post has an ID of 123 it will have a class of post-123
.
This code snippet goes in a core functionality plugin or Code Snippets.
/**
* Display Posts - post ID class
* @see https://displayposts.com/2019/08/29/add-post-id-class-to-each-listing-item/
*
* @param array $classes
* @param object $post
* @return array $classes
*/
function be_dps_post_id_class( $classes, $post ) {
$classes[] = 'post-' . get_the_ID();
return $classes;
}
add_filter( 'display_posts_shortcode_post_class', 'be_dps_post_id_class', 10, 2 );