<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12917] trunk/wp-includes/general-template.php: Introduce get_the_date().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12917">12917</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-01 16:28:54 +0000 (Mon, 01 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce get_the_date(). Props jeremyclarke. fixes <a href="http://trac.wordpress.org/ticket/11264">#11264</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesgeneraltemplatephp">trunk/wp-includes/general-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/general-template.php (12916 => 12917)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/general-template.php        2010-02-01 08:12:56 UTC (rev 12916)
+++ trunk/wp-includes/general-template.php        2010-02-01 16:28:54 UTC (rev 12917)
</span><span class="lines">@@ -1256,40 +1256,69 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Display or Retrieve the date the post was written.
</del><ins>+ * Display or Retrieve the date the current $post was written (once per date)
</ins><span class="cx"> *
</span><span class="cx"> * Will only output the date if the current post's date is different from the
</span><span class="cx"> * previous one output.
</span><ins>+
+ * 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.
</ins><span class="cx"> *
</span><ins>+ * HTML output can be filtered with 'the_date'.
+ * Date string output can be filtered with 'get_the_date'.
+ *
</ins><span class="cx"> * @since 0.71
</span><del>- *
</del><ins>+ * @uses get_the_date()
</ins><span class="cx"> * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
</span><span class="cx"> * @param string $before Optional. Output before the date.
</span><span class="cx"> * @param string $after Optional. Output after the date.
</span><span class="cx"> * @param bool $echo Optional, default is display. Whether to echo the date or return it.
</span><span class="cx"> * @return string|null Null if displaying, string if retrieving.
</span><span class="cx"> */
</span><del>-function the_date($d='', $before='', $after='', $echo = true) {
-        global $post, $day, $previousday;
</del><ins>+function the_date( $d = '', $before = '', $after = '', $echo = true ) {
+        global $day, $previousday;
</ins><span class="cx">         $the_date = '';
</span><span class="cx">         if ( $day != $previousday ) {
</span><span class="cx">                 $the_date .= $before;
</span><del>-                if ( $d=='' )
-                        $the_date .= mysql2date(get_option('date_format'), $post->post_date);
-                else
-                        $the_date .= mysql2date($d, $post->post_date);
</del><ins>+                $the_date .= get_the_date( $d );
</ins><span class="cx">                 $the_date .= $after;
</span><span class="cx">                 $previousday = $day;
</span><span class="cx">
</span><del>-        $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
-        if ( $echo )
-                echo $the_date;
-        else
-                return $the_date;
</del><ins>+                $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
+
+                if ( $echo )
+                        echo $the_date;
+                else
+                        return $the_date;
</ins><span class="cx">         }
</span><ins>+
+        return null;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * 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);
+}
+
+/**
</ins><span class="cx"> * Display the date on which the post was last modified.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.1.0
</span></span></pre>
</div>
</div>
</body>
</html>