render_block_core_comment_template

函数
render_block_core_comment_template ( $attributes, $content, $block )
参数
  • (array) $attributes Block attributes.
    Required:
  • (string) $content Block default content.
    Required:
  • (WP_Block) $block Block instance.
    Required:
返回值
  • (string) Returns the HTML representing the comments using the layout defined by the block's inner blocks.
定义位置
相关方法
register_block_core_comment_templaterender_block_core_comment_daterender_block_core_post_templaterender_block_core_comments_titlerender_block_core_comment_content
引入
-
弃用
-

render_block_core_comment_template: 这个函数用来渲染WordPress中的评论模板块。评论模板块是用来显示访问者可以用来给文章添加评论的表单: 这个函数负责生成评论模板块的HTML标记。

渲染服务器上的`core/comment-template`区块。

function render_block_core_comment_template( $attributes, $content, $block ) {
	// Bail out early if the post ID is not set for some reason.
	if ( empty( $block->context['postId'] ) ) {
		return '';
	}

	if ( post_password_required( $block->context['postId'] ) ) {
		return;
	}

	$comment_query = new WP_Comment_Query(
		build_comment_query_vars_from_block( $block )
	);

	// Get an array of comments for the current post.
	$comments = $comment_query->get_comments();
	if ( count( $comments ) === 0 ) {
		return '';
	}

	$comment_order = get_option( 'comment_order' );

	if ( 'desc' === $comment_order ) {
		$comments = array_reverse( $comments );
	}

	$wrapper_attributes = get_block_wrapper_attributes();

	return sprintf(
		'<ol %1$s>%2$s</ol>',
		$wrapper_attributes,
		block_core_comment_template_render_comments( $comments, $block )
	);
}

常见问题

FAQs
查看更多 >