Introduce get_the_date(). Props jeremyclarke. fixes #11264
git-svn-id: http://svn.automattic.com/wordpress/trunk@12917 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
94af70dea8
commit
f1a954d944
|
@ -1256,37 +1256,66 @@ function the_date_xml() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display or Retrieve the date the post was written.
|
* 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
|
* Will only output the date if the current post's date is different from the
|
||||||
* previous one output.
|
* 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
|
* @since 0.71
|
||||||
*
|
* @uses get_the_date()
|
||||||
* @param string $d Optional. PHP date format defaults to the date_format option if not specified.
|
* @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 $before Optional. Output before the date.
|
||||||
* @param string $after Optional. Output after 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.
|
* @param bool $echo Optional, default is display. Whether to echo the date or return it.
|
||||||
* @return string|null Null if displaying, string if retrieving.
|
* @return string|null Null if displaying, string if retrieving.
|
||||||
*/
|
*/
|
||||||
function the_date($d='', $before='', $after='', $echo = true) {
|
function the_date( $d = '', $before = '', $after = '', $echo = true ) {
|
||||||
global $post, $day, $previousday;
|
global $day, $previousday;
|
||||||
$the_date = '';
|
$the_date = '';
|
||||||
if ( $day != $previousday ) {
|
if ( $day != $previousday ) {
|
||||||
$the_date .= $before;
|
$the_date .= $before;
|
||||||
if ( $d=='' )
|
$the_date .= get_the_date( $d );
|
||||||
$the_date .= mysql2date(get_option('date_format'), $post->post_date);
|
|
||||||
else
|
|
||||||
$the_date .= mysql2date($d, $post->post_date);
|
|
||||||
$the_date .= $after;
|
$the_date .= $after;
|
||||||
$previousday = $day;
|
$previousday = $day;
|
||||||
|
|
||||||
$the_date = apply_filters('the_date', $the_date, $d, $before, $after);
|
$the_date = apply_filters('the_date', $the_date, $d, $before, $after);
|
||||||
if ( $echo )
|
|
||||||
echo $the_date;
|
if ( $echo )
|
||||||
else
|
echo $the_date;
|
||||||
return $the_date;
|
else
|
||||||
|
return $the_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the date the current $post was written.
|
||||||
|
*
|
||||||
|
* Unlike the_date() this function will always return the date.
|
||||||
|
* Modify output with 'get_the_date' filter.
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*
|
||||||
|
* @param string $d Optional. PHP date format defaults to the date_format option if not specified.
|
||||||
|
* @return string|null Null if displaying, string if retrieving.
|
||||||
|
*/
|
||||||
|
function get_the_date( $d = '' ) {
|
||||||
|
global $post, $day;
|
||||||
|
$the_date = '';
|
||||||
|
|
||||||
|
if ( '' == $d )
|
||||||
|
$the_date .= mysql2date(get_option('date_format'), $post->post_date);
|
||||||
|
else
|
||||||
|
$the_date .= mysql2date($d, $post->post_date);
|
||||||
|
|
||||||
|
return apply_filters('get_the_date', $the_date, $d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue