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’區塊。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
);
}
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 ); }
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
檢視更多 >