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`区块。

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
查看更多 >