the_date

函式
the_date ( $format = '', $before = '', $after = '', $echo = true )
引數
  • (string) $format Optional. PHP date format. Defaults to the 'date_format' option.
    Required:
    Default: (empty)
  • (string) $before Optional. Output before the date. Default empty.
    Required:
    Default: (empty)
  • (string) $after Optional. Output after the date. Default empty.
    Required:
    Default: (empty)
  • (bool) $echo Optional. Whether to echo the date or return it. Default true.
    Required:
    Default: true
返回值
  • (string|void) String if retrieving.
定義位置
相關方法
get_the_datethe_date_xmlthe_timethe_titlethe_terms
引入
0.71
棄用
-

the_date – 這個函式用來顯示一個文章或頁面的日期。它有幾個引數,允許自定義輸出,如日期格式和是否連結到該日期的檔案頁。

顯示或檢索當前文章的寫作日期(每個日期一次)。

只有噹噹前文章的日期與前一個文章的日期不同時,才會輸出日期。

也就是說,在迴圈中顯示的每一天的文章只顯示一個日期列表,即使該函式為每個文章呼叫了幾次。

HTML輸出可以用’the_date’來過濾。日期字串的輸出可以用’get_the_date’來過濾。

function the_date( $format = '', $before = '', $after = '', $echo = true ) {
	global $currentday, $previousday;

	$the_date = '';

	if ( is_new_day() ) {
		$the_date    = $before . get_the_date( $format ) . $after;
		$previousday = $currentday;
	}

	/**
	 * Filters the date a post was published for display.
	 *
	 * @since 0.71
	 *
	 * @param string $the_date The formatted date string.
	 * @param string $format   PHP date format.
	 * @param string $before   HTML output before the date.
	 * @param string $after    HTML output after the date.
	 */
	$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after );

	if ( $echo ) {
		echo $the_date;
	} else {
		return $the_date;
	}
}

常見問題

FAQs
檢視更多 >