render_block_core_post_date

函数
render_block_core_post_date ( $attributes, $content, $block )
参数
  • (array) $attributes Block attributes.
    Required:
  • (string) $content Block default content.
    Required:
  • (WP_Block) $block Block instance.
    Required:
返回值
  • (string) Returns the filtered post date for the current post wrapped inside "time" tags.
定义位置
相关方法
render_block_core_post_termsrender_block_core_post_titlerender_block_core_post_templaterender_block_core_post_authorregister_block_core_post_date
引入
-
弃用
-

render_block_core_post_date: 这个函数用来渲染WordPress中的文章的日期。它负责为文章的发表日期生成HTML标记,用户可以自定义。

在服务器上呈现`core/post-date’区块。

function render_block_core_post_date( $attributes, $content, $block ) {
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

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

	if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
		$formatted_date   = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
		$unformatted_date = esc_attr( get_the_modified_date( 'c', $post_ID ) );
	} else {
		$formatted_date   = get_the_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
		$unformatted_date = esc_attr( get_the_date( 'c', $post_ID ) );
	}

	if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
		$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
	}

	return sprintf(
		'<div %1$s><time datetime="%2$s">%3$s</time></div>',
		$wrapper_attributes,
		$unformatted_date,
		$formatted_date
	);
}

常见问题

FAQs
查看更多 >