date:日付
data:データ・資料・情報 database
the_date()
構文
the_date( $format[オプション], $before[オプション], $after[オプション], $echo[オプション] );
the_date()の詳細
動 作
記事の投稿・更新日時を出力する。
返り値
$echoがfalseなら投稿日を返す。
それ以外はnull(何も返さない)
引 数
$format[オプション]
(文字列)日時の出力形式
(デフォルト)WordPressの管理画面の設定。
$before[オプション]
(文字列)日付の前に記述するコードやテキスト。
(デフォルト)なし
$after[オプション]
(文字列)日付の後に記述するコードやテキスト。
(デフォルト)なし
$echo[オプション]
(true/false)
true 日付をページ内に出力
false PHPで使用できる値で日付を返す。
(デフォルト)true
the_date()のコード
参照:wp-includes/general-template.php
<?php /** 2330 * Display or Retrieve the date the current post was written (once per date) 2331 * 2332 * Will only output the date if the current post's date is different from the 2333 * previous one output. 2334 * 2335 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the 2336 * function is called several times for each post. 2337 * 2338 * HTML output can be filtered with 'the_date'. 2339 * Date string output can be filtered with 'get_the_date'. 2340 * 2341 * @since 0.71 2342 * 2343 * @global string $currentday The day of the current post in the loop. 2344 * @global string $previousday The day of the previous post in the loop. 2345 * 2346 * @param string $d Optional. PHP date format defaults to the date_format option if not specified. 2347 * @param string $before Optional. Output before the date. 2348 * @param string $after Optional. Output after the date. 2349 * @param bool $echo Optional, default is display. Whether to echo the date or return it. 2350 * @return string|void String if retrieving. 2351 */ 2352 function the_date( $d = '', $before = '', $after = '', $echo = true ) { 2353 global $currentday, $previousday; 2354 2355 $the_date = ''; 2356 2357 if ( is_new_day() ) { 2358 $the_date = $before . get_the_date( $d ) . $after; 2359 $previousday = $currentday; 2360 } 2361 2362 /** 2363 * Filters the date a post was published for display. 2364 * 2365 * @since 0.71 2366 * 2367 * @param string $the_date The formatted date string. 2368 * @param string $d PHP date format. Defaults to 'date_format' option 2369 * if not specified. 2370 * @param string $before HTML output before the date. 2371 * @param string $after HTML output after the date. 2372 */ 2373 $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); 2374 2375 if ( $echo ) { 2376 echo $the_date; 2377 } else { 2378 return $the_date; 2379 } 2380 } 2381 2382 /** 2383 * Retrieve the date on which the post was written. 2384 * 2385 * Unlike the_date() this function will always return the date. 2386 * Modify output with the {@see 'get_the_date'} filter. 2387 * 2388 * @since 3.0.0 2389 * 2390 * @param string $d Optional. PHP date format defaults to the date_format option if not specified. 2391 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. 2392 * @return false|string Date the current post was written. False on failure. 2393 */ 2394 function get_the_date( $d = '', $post = null ) { 2395 $post = get_post( $post ); 2396 2397 if ( ! $post ) { 2398 return false; 2399 } 2400 2401 if ( '' == $d ) { 2402 $the_date = get_post_time( get_option( 'date_format' ), false, $post, true ); 2403 } else { 2404 $the_date = get_post_time( $d, false, $post, true ); 2405 } 2406 2407 /** 2408 * Filters the date a post was published. 2409 * 2410 * @since 3.0.0 2411 * 2412 * @param string $the_date The formatted date. 2413 * @param string $d PHP date format. Defaults to 'date_format' option 2414 * if not specified. 2415 * @param int|WP_Post $post The post object or ID. 2416 */ 2417 return apply_filters( 'get_the_date', $the_date, $d, $post ); 2418 } ?>