目录
描述
Displays or returns the date of a post, or a set of posts if published on the same day.
Use
<?php the_time( get_option( 'date_format' ) ); ?>
to add the date set in the admin interface.This tag must be used within The Loop.
the_date() 描述
用法
<?php the_date( $format, $before, $after, $echo ); ?>
the_date() 用法
参数
$format
(string) (可选) The format for the date. Defaults to the date format configured in your WordPress options. See Formatting Date and Time.
默认值: F j, Y)
$before
(string) (可选) Text to place before the date.
默认值: None
$after
(string) (可选) Text to place after the date
默认值: None
$echo
(boolean) (可选) Display the date (TRUE), or return the date to be used in PHP (FALSE).
默认值: TRUE
the_date() 参数
示例
Default Usage
Displays the date using defaults.
1 2 3 4 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ <?php the_date(); ?> |
Date as Year, Month, Date in Heading
Displays the date using the '2007-07-23'
format (ex: 2004-11-30), inside an <h2> tag.
1 2 3 4 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ <?php the_date('Y-m-d', '<h2>', '</h2>'); ?> |
Date in Heading Using $my_date Variable
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.
1 2 3 4 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ <?php $my_date = the_date('', '<h2>', '</h2>', FALSE); echo $my_date; ?> |
the_date() 示例
注意
- Affects the return value of the is_new_day() function.
the_date() 注意
历史
添加于 版本: 0.71
the_date() 历史
源文件
the_date() 函数的代码位于 wp-includes/general-template.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
/* ---------------------------------- * wordpress之魂 © http://wphun.com * ---------------------------------- */ /** * Display or Retrieve the date the current post was written (once per date) * * Will only output the date if the current post's date is different from the * previous one output. * * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the * function is called several times for each post. * * HTML output can be filtered with 'the_date'. * Date string output can be filtered with 'get_the_date'. * * @since 0.71 * * @global string|int|bool $currentday * @global string|int|bool $previousday * * @param string $d Optional. PHP date format defaults to the date_format option if not specified. * @param string $before Optional. Output before the date. * @param string $after Optional. Output after the date. * @param bool $echo Optional, default is display. Whether to echo the date or return it. * @return string|void String if retrieving. */ function the_date( $d = '', $before = '', $after = '', $echo = true ) { global $currentday, $previousday; if ( $currentday != $previousday ) { $the_date = $before . get_the_date( $d ) . $after; $previousday = $currentday; /** * Filter the date a post was published for display. * * @since 0.71 * * @param string $the_date The formatted date string. * @param string $d PHP date format. Defaults to 'date_format' option * if not specified. * @param string $before HTML output before the date. * @param string $after HTML output after the date. */ $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); if ( $echo ) echo $the_date; else return $the_date; } } |
the_date() 源文件
- 原文:http://codex.wordpress.org/Function_Reference/the_date
- 翻译:黄聪@WordPress之魂