WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If the post date is today (6 posts)

  1. Douglas Karr
    Member
    Posted 7 years ago #

    I am trying to change my template to simply state today instead of the actual date when the post date equals todays date.

    I tried:
    <?php if($post->post_date==date()) { echo 'today'; } ?>

    This didn't seem to work at all. Any ideas?

  2. MichaelH
    Member
    Posted 7 years ago #

    If it is in the loop can't you do something like

    the_date('F j, Y')==date('F j, Y')

    See:

    Template_Tags/the_date

  3. Douglas Karr
    Member
    Posted 7 years ago #

    Whenever I actually type the_date, it actually displays. I'm not sure why... but it's a pain in the butt! :)

  4. MichaelH
    Member
    Posted 7 years ago #

    Well of course it displays the date because that is what it is supposed to do! As you are finding, my suggestion won't work.

    Looking at some of the core code you might be able to do something like:
    $post_date = mysql2date("Ymd\TH:i:s", $post->post_date_gmt);

    and then use $post_date in your test.

    I'll have to play around with that...

  5. MichaelH
    Member
    Posted 7 years ago #

    Well this will assign the post date to a variable
    <?php $post_date = mysql2date("Ymd", $post->post_date_gmt); ?>

    so your test would be:

    $post_date==date('Ymd')

  6. Douglas Karr
    Member
    Posted 7 years ago #

    That was the key, MichaelH! Thanks! I've now got a specific class applied to my date on my posts that provides a note that it was 'Today'. Woohoo!

Topic Closed

This topic has been closed to new replies.

About this Topic