函数原型
comment_class( string|string[] $css_class = ”, int|WP_Comment $comment = null, int|WP_Post $post = null, bool $display = true ): void|string
函数描述
Generates semantic classes for each comment element.
是否弃用
未弃用
函数参数
-
$css_class
string|string[]
Optional - One or more classes to add to the class list.
Default:
'' -
$comment
int|WP_Comment
Optional - Comment ID or WP_Comment object. Default current comment.
Default:
null -
$post
int|WP_Post
Optional - Post ID or WP_Post object. Default current post.
Default:
null -
$display
bool
Optional - Whether to print or return the output.
Default:
true
函数返回值
void|string Void if $display argument is true, comment classes if $display is false.
函数位置
File: wp-includes/comment-template.php.
函数源码
function comment_class( $css_class = '', $comment = null, $post = null, $display = true ) {
// Separates classes with a single space, collates classes for comment DIV.
$css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post ) ) . '"';
if ( $display ) {
echo $css_class;
} else {
return $css_class;
}
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.4.0 | Added the ability for $comment to also accept a WP_Comment object. |
| 2.7.0 | Introduced. |

