get_the_date

函式
get_the_date ( $format = '', $post = null )
引數
  • (string) $format Optional. PHP date format. Defaults to the 'date_format' option.
    Required:
    Default: (empty)
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default current post.
    Required:
    Default: null
返回值
  • (string|int|false) Date the current post was written. False on failure.
定義位置
相關方法
get_theme_dataget_theme_updatesget_the_timeget_the_idthe_date
引入
3.0.0
棄用
-

get_the_date: 這個函式檢索當前文章或頁面的日期,根據WordPress設定中的日期格式進行格式化。它需要兩個可選引數:日期格式和文章ID。它以字串形式返回格式化的日期。

檢索文章的寫作日期。

與the_date()不同的是,這個函式將總是返回日期。用{@see ‘get_the_date’}過濾器修改輸出。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_the_date( $format = '', $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
$the_date = get_post_time( $_format, false, $post, true );
/**
* Filters the date a post was published.
*
* @since 3.0.0
*
* @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
* @param string $format PHP date format.
* @param WP_Post $post The post object.
*/
return apply_filters( 'get_the_date', $the_date, $format, $post );
}
function get_the_date( $format = '', $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); $the_date = get_post_time( $_format, false, $post, true ); /** * Filters the date a post was published. * * @since 3.0.0 * * @param string|int $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. * @param string $format PHP date format. * @param WP_Post $post The post object. */ return apply_filters( 'get_the_date', $the_date, $format, $post ); }
function get_the_date( $format = '', $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );

	$the_date = get_post_time( $_format, false, $post, true );

	/**
	 * Filters the date a post was published.
	 *
	 * @since 3.0.0
	 *
	 * @param string|int  $the_date Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
	 * @param string      $format   PHP date format.
	 * @param WP_Post     $post     The post object.
	 */
	return apply_filters( 'get_the_date', $the_date, $format, $post );
}

常見問題

FAQs
檢視更多 >