Support » Fixing WordPress » Help with the_date vs. the_time

  • Hello again. *rolls eyes* One of these days I’m going to be done with my site and won’t be starting a thread a day. Anyways. Today’s hurdle: I’m trying to display the date on my site with a different class for each date value (the day in one size font, the month in another, the year in a third). I’m using multiple instances of <?php the_date() ?>, but its only calling the first value (in my case, the numerical day) without displaying the month or the year. So I tried using <?php the_time() ?>, and now it’s displaying everything, but on every post. Is there a way to get <?php the_time() ?> to behave like <?php the_date() ?> and not display on every post? Thanks in advance for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t think it will work – the whole idea of having two different template tags is to make them behave differently. See
    Date and time tags

    Hrmmm…and you’re meaning that vice-versa as well? As in not only can you not force the occurence of the_time down, but there’s also absolutely no way on earth to call the_date more than once?

    Another question – I was looking through the tags and noticed that example three on the_date says something about assigning the date to the $my_date variable. What’s that, and how can I work with it?

    Correct, the_date is meant to only be called once. That’s why when it’s called for the 2nd post on a particular day, nothing outputs.

    You’d need a plugin to do what you are looking for.

    Since the_date() can be configured to display the time, and the_time() likewise with the date, I’d look hard at the format parameter on both tags to see how to alter date and/or time formatting based on how you wish to implement them.

    RE: $my_date: The example is just showing anyone who might need to use the date of a post in their PHP scripting how to pull it from the_date().

    Hey, I had the exact same problem. Here’s what I did… It’s an ugly, ugly hack but it seems to work. I copied the_date function and then cut out the If statement at the top that prevented you from using the date more than once. Then, I copied this into an “extradate.php” file and included it at the top “require(‘extradate.php’);”.


    function extra_date($d=”, $before=”, $after=”, $echo = true) {
    global $id, $post, $day, $previousday, $newday;
    $the_date = ”;

    if ( $d==” )
    $the_date .= mysql2date(get_settings(‘date_format’), $post->post_date);
    $the_date .= mysql2date($d, $post->post_date);
    $the_date .= $after;
    $previousday = $day;

    $the_date = apply_filters(‘the_date’, $the_date, $d, $before, $after);
    if ( $echo )
    echo $the_date;
    return $the_date;


    now i can call extra_date(); as much as I please.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help with the_date vs. the_time’ is closed to new replies.