WordPress.org

Ready to get started?Download WordPress

Forums

Help with the_date vs. the_time (6 posts)

  1. Lumina
    Member
    Posted 9 years ago #

    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!

  2. moshu
    Member
    Posted 9 years ago #

    I don't think it will work - the whole idea of having two different template tags is to make them behave differently. See http://codex.wordpress.org/Template_Tags
    Date and time tags

  3. Lumina
    Member
    Posted 9 years ago #

    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?

  4. Nick Momrik
    Member
    Posted 9 years ago #

    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.

  5. Kafkaesqui

    Posted 9 years ago #

    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().

  6. ericmcgregor
    Member
    Posted 8 years ago #

    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');".

    <?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);
    else
    $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;
    else
    return $the_date;
    }

    ?>

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.