WordPress函数:comment_class 为每个评论元素生成 class

江河/ 2023年06月12日/ WordPress/ 浏览 671

函数原型:


comment_class( string|string[] $css_class = '', int|WP_Comment $comment = null, int|WP_Post $post = null, bool $display = true ): void|string


为每个评论元素生成 class。


如果$display参数为true,则为Void;如果$display为false,则为评论类。


参数说明:


$css_class,要添加到类列表中的一个或多个类。默认为空。


$comment,注释ID或WP_Comment对象。默认当前评论。


$post,文章ID 或 文章对象。默认为当前文章。


$display,是打印还是返回输出。


函数源码:


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;
	}
}


使用举例:


<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">


发表评论

暂无评论,抢个沙发...

客服 工单