render_block_core_post_author_biography

函式
render_block_core_post_author_biography ( $attributes, $content, $block )
引數
  • (array) $attributes Block attributes.
    Required:
  • (string) $content Block default content.
    Required:
  • (WP_Block) $block Block instance.
    Required:
返回值
  • (string) Returns the rendered post author biography block.
定義位置
相關方法
register_block_core_post_author_biographyrender_block_core_post_authorregister_block_core_post_authorrender_block_core_post_daterender_block_core_post_featured_image
引入
-
棄用
-

render_block_core_post_author_biography: 這個函式用來渲染WordPress中的作者傳記塊。作者傳記塊顯示關於一個文章的作者的資訊,包括他們的名字、照片和簡短的簡歷: 這個函式負責生成作者傳記塊的HTML標記。

在伺服器上呈現`core/post-author-biography’區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function render_block_core_post_author_biography( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$author_id = get_post_field( 'post_author', $block->context['postId'] );
if ( empty( $author_id ) ) {
return '';
}
$author_biography = get_the_author_meta( 'description', $author_id );
if ( empty( $author_biography ) ) {
return '';
}
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_biography . '</div>';
}
function render_block_core_post_author_biography( $attributes, $content, $block ) { if ( ! isset( $block->context['postId'] ) ) { return ''; } $author_id = get_post_field( 'post_author', $block->context['postId'] ); if ( empty( $author_id ) ) { return ''; } $author_biography = get_the_author_meta( 'description', $author_id ); if ( empty( $author_biography ) ) { return ''; } $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_biography . '</div>'; }
function render_block_core_post_author_biography( $attributes, $content, $block ) {
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$author_id = get_post_field( 'post_author', $block->context['postId'] );
	if ( empty( $author_id ) ) {
		return '';
	}

	$author_biography = get_the_author_meta( 'description', $author_id );
	if ( empty( $author_biography ) ) {
		return '';
	}

	$align_class_name   = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

	return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_biography . '</div>';
}

常見問題

FAQs
檢視更多 >