WordPress.org

Make WordPress Core

Changeset 12917


Ignore:
Timestamp:
02/01/2010 04:28:54 PM (9 years ago)
Author:
ryan
Message:

Introduce get_the_date(). Props jeremyclarke. fixes #11264

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/general-template.php

    r12733 r12917  
    12571257
    12581258/**
    1259  * Display or Retrieve the date the post was written.
     1259 * Display or Retrieve the date the current $post was written (once per date)
    12601260 *
    12611261 * Will only output the date if the current post's date is different from the
    12621262 * previous one output.
     1263
     1264 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
     1265 * function is called several times for each post.
     1266 *
     1267 * HTML output can be filtered with 'the_date'.
     1268 * Date string output can be filtered with 'get_the_date'.
    12631269 *
    12641270 * @since 0.71
    1265  *
     1271 * @uses get_the_date()
    12661272 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
    12671273 * @param string $before Optional. Output before the date.
     
    12701276 * @return string|null Null if displaying, string if retrieving.
    12711277 */
    1272 function the_date($d='', $before='', $after='', $echo = true) {
    1273     global $post, $day, $previousday;
     1278function the_date( $d = '', $before = '', $after = '', $echo = true ) {
     1279    global $day, $previousday;
    12741280    $the_date = '';
    12751281    if ( $day != $previousday ) {
    12761282        $the_date .= $before;
    1277         if ( $d=='' )
    1278             $the_date .= mysql2date(get_option('date_format'), $post->post_date);
    1279         else
    1280             $the_date .= mysql2date($d, $post->post_date);
     1283        $the_date .= get_the_date( $d );
    12811284        $the_date .= $after;
    12821285        $previousday = $day;
    12831286
    1284     $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
    1285     if ( $echo )
    1286         echo $the_date;
     1287        $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
     1288
     1289        if ( $echo )
     1290            echo $the_date;
     1291        else
     1292            return $the_date;
     1293    }
     1294
     1295    return null;
     1296}
     1297
     1298/**
     1299 * Retrieve the date the current $post was written.
     1300 *
     1301 * Unlike the_date() this function will always return the date.
     1302 * Modify output with 'get_the_date' filter.
     1303 *
     1304 * @since 3.0.0
     1305 *
     1306 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
     1307 * @return string|null Null if displaying, string if retrieving.
     1308 */
     1309function get_the_date( $d = '' ) {
     1310    global $post, $day;
     1311    $the_date = '';
     1312
     1313    if ( '' == $d )
     1314        $the_date .= mysql2date(get_option('date_format'), $post->post_date);
    12871315    else
    1288         return $the_date;
    1289     }
     1316        $the_date .= mysql2date($d, $post->post_date);
     1317
     1318    return apply_filters('get_the_date', $the_date, $d);
    12901319}
    12911320
Note: See TracChangeset for help on using the changeset viewer.