render_block_core_comments_title

函数
render_block_core_comments_title ( $attributes )
参数
  • (array) $attributes Block attributes.
    Required:
返回值
  • (string) Return the post comments title.
定义位置
相关方法
register_block_core_comments_titlerender_block_core_comment_daterender_block_core_commentsrender_block_core_comment_edit_linkrender_block_core_post_title
引入
-
弃用
-

render_block_core_comments_title: 这个函数用来渲染WordPress中的评论标题块。评论标题块显示评论部分的标题: 这个函数负责生成评论标题块的HTML标记。

在服务器上渲染`core/comments-title’区块。

function render_block_core_comments_title( $attributes ) {

	if ( post_password_required() ) {
		return;
	}

	$align_class_name    = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
	$show_post_title     = ! empty( $attributes['showPostTitle'] ) && $attributes['showPostTitle'];
	$show_comments_count = ! empty( $attributes['showCommentsCount'] ) && $attributes['showCommentsCount'];
	$wrapper_attributes  = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
	$comments_count      = get_comments_number();
	/* translators: %s: Post title. */
	$post_title = sprintf( __( '“%s”' ), get_the_title() );
	$tag_name   = 'h2';
	if ( isset( $attributes['level'] ) ) {
		$tag_name = 'h' . $attributes['level'];
	}

	if ( '0' === $comments_count ) {
		return;
	}

	if ( $show_comments_count ) {
		if ( $show_post_title ) {
			if ( '1' === $comments_count ) {
				/* translators: %s: Post title. */
				$comments_title = sprintf( __( 'One response to %s' ), $post_title );
			} else {
				$comments_title = sprintf(
					/* translators: 1: Number of comments, 2: Post title. */
					_n(
						'%1$s response to %2$s',
						'%1$s responses to %2$s',
						$comments_count
					),
					number_format_i18n( $comments_count ),
					$post_title
				);
			}
		} elseif ( '1' === $comments_count ) {
			$comments_title = __( 'One response' );
		} else {
			$comments_title = sprintf(
				/* translators: %s: Number of comments. */
				_n( '%s response', '%s responses', $comments_count ),
				number_format_i18n( $comments_count )
			);
		}
	} elseif ( $show_post_title ) {
		if ( '1' === $comments_count ) {
			/* translators: %s: Post title. */
			$comments_title = sprintf( __( 'Response to %s' ), $post_title );
		} else {
			/* translators: %s: Post title. */
			$comments_title = sprintf( __( 'Responses to %s' ), $post_title );
		}
	} elseif ( '1' === $comments_count ) {
		$comments_title = __( 'Response' );
	} else {
		$comments_title = __( 'Responses' );
	}

	return sprintf(
		'<%1$s id="comments" %2$s>%3$s</%1$s>',
		$tag_name,
		$wrapper_attributes,
		$comments_title
	);
}

常见问题

FAQs
查看更多 >