您可以根据用户角色更新post类,以包括一个附加选择器,该选择器添加自定义样式,即
function add_contributor_class_to_single_post( $classes ) {
if ( is_single() ) {
$post_id = get_queried_object_id();
$author_ID = get_post_field( \'post_author\', $post_id );
$author_data = get_userdata( $author_ID );
if (in_array( \'contributor\', $author_data->roles)) {
// add post class
array_push( $classes, \'user-contributor\' );
}
}
return $classes;
}
add_filter( \'post_class\', \'add_contributor_class_to_single_post\' );
然后将css更新为:
.type-post.user-contributor { border: 10px solid #fff }
.type-post { border: 20px solid #000 }