render_block_core_read_more

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

render_block_core_read_more: 這個函式用來渲染WordPress中的塊的”Read More”連結。它通常與”文章摘錄”塊一起使用,它顯示一篇較長文章的簡短摘錄。閱讀更多”連結允許使用者點選進入完整的文章。

在伺服器上渲染`core/read-more`區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function render_block_core_read_more( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$post_ID = $block->context['postId'];
$justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) );
$more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' );
return sprintf(
'<a %1s href="%2s" target="%3s">%4s</a>',
$wrapper_attributes,
get_the_permalink( $post_ID ),
esc_attr( $attributes['linkTarget'] ),
$more_text
);
}
function render_block_core_read_more( $attributes, $content, $block ) { if ( ! isset( $block->context['postId'] ) ) { return ''; } $post_ID = $block->context['postId']; $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); return sprintf( '<a %1s href="%2s" target="%3s">%4s</a>', $wrapper_attributes, get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), $more_text ); }
function render_block_core_read_more( $attributes, $content, $block ) {
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$post_ID            = $block->context['postId'];
	$justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}";
	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) );
	$more_text          = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' );
	return sprintf(
		'<a %1s href="%2s" target="%3s">%4s</a>',
		$wrapper_attributes,
		get_the_permalink( $post_ID ),
		esc_attr( $attributes['linkTarget'] ),
		$more_text
	);
}

常見問題

FAQs
檢視更多 >