在我们的WordPress页面上,我们是几个写文章的人。所有这些人都扮演着不同的用户角色。有些是编辑,有些只是作者,我是管理员。
我知道你可以通过写作突出评论或帖子作者的回复
.commentlist .bypostauthor {
# some styles
}
但我如何才能更改它,以便突出显示以下用户角色(作者、编辑和管理员)的注册用户所写的每条评论或回复?谢谢你帮我:)
在我们的WordPress页面上,我们是几个写文章的人。所有这些人都扮演着不同的用户角色。有些是编辑,有些只是作者,我是管理员。
我知道你可以通过写作突出评论或帖子作者的回复
.commentlist .bypostauthor {
# some styles
}
但我如何才能更改它,以便突出显示以下用户角色(作者、编辑和管理员)的注册用户所写的每条评论或回复?谢谢你帮我:)
有一个过滤器叫做comment_class
为此:
apply_filters( \'comment_class\', $classes, $class, $comment->comment_ID, $comment, $post_id );
只需使用参数comment
这是一个对象$comment->user_id
这对于获取用户角色和添加类很有用。编辑:
add_filter( \'comment_class\', \'wpse_253517_comment_class\', 10, 5 );
function wpse_253517_comment_class( $classes, $class, $comment_ID, $comment, $post_id ) {
if ( 0 === (int) $comment->user_id ) {
return $classes;
}
$user_data = get_userdata( $comment->user_id );
$role = reset( $user_data->roles );
switch( $role ) {
case \'subscriber\':
$classes[] = \'is-subscriber\';
break;
// here would be other cases, other roles
default:
return $classes;
}
return $classes;
}
在此处输入代码 <ol class=\"commentlist\"> fsdfds <?php wp_list_comments( apply_filters( \'woocommerce_product_review_list_args\', array( \'callback\' => \'woocommerce_comments\' ) ) ); ?> </ol&