- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
テンプレートタグ/the date
目次
説明
記事の投稿/更新日を出力。PHPの日付文法が使用できる。同じ日に複数の記事がある場合は、最初の記事とともに一度だけ出力される。
特記事項::同じ日の下で公開ページに複数の記事がある場合、the_date()は最初の記事の日付が表示されます(つまり、 the_date()の最初のインスタンス)。同じ日で公開の記事の日付を繰り返すには、日付固有の形式の文字列でテンプレートタグthe_time() または(3.0以降)get_the_date()を使用する必要があります。
Use<?php the_time( get_option( 'date_format' ) ); ?>
管理画面に設定された日付を追加します。このタグはループ内で使用します。
使い方
<?php the_date( $format, $before, $after, $echo ); ?>
パラメータ
- $format
- (文字列) (オプション) 日時の出力形式。デフォルト値は管理画面のオプションで設定した形式。Formatting Date and Timeを参照。
- 初期値: F j, Y)
- $before
- (文字列) (オプション) 投稿/更新日の直前に出力するコードやテキスト。デフォルト値は空。
- 初期値: なし
- $after
- (文字列) (オプション) 投稿/更新日の直後に出力するコードやテキスト。デフォルト値は空。
- 初期値: なし
- $echo
- (true/false) (オプション) (TRUE)なら日付をページ内に出力、(FALSE)ならPHPで使用できる値として日付を返す。
- 初期値: TRUE
戻り値
(string|null) 表示の場合はnull、文字列ならば取得する。
用例
デフォルトの使い方
日付を表示する:
<?php the_date(); ?>
年月日を表示する
<h2> タグの中に '2007-07-23'
形式(ex: 2004-11-30)で日付を表示する:
<?php the_date('Y-m-d', '<h2>', '</h2>'); ?>
$my_date 変数を使った見出しの日付
Returns the date in the default format inside an <h2> tag and assigns it to the $my_date variable. The variable's value is then displayed with the PHP echo command.
<?php $my_date = the_date('', '<h2>', '</h2>', FALSE); echo $my_date; ?>
注
- is_new_day() / en 関数の戻り値に影響を与えます。
更新履歴
Since: 0.71
ソースファイル
the_date() は wp-includes/general-template.php
にあります。
外部リソース
http://mako-wis.hatenablog.com/entry/2014/03/27/001218 the_dateとget_the_dateの違い
関連
日時に関連するタグ: get_calendar(), get_day_link(), get_month_link(), get_the_date(), get_the_time(), get_year_link(), single_month_title(), the_date(), the_date_xml(), the_modified_date(), get_the_modified_date(), the_modified_time(), get_the_modified_time(), the_time()
最新英語版: WordPress Codex » Function_Reference/the_date (最新版との差分)