• Resolved douglaskarr

    (@douglaskarr)


    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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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

    Thread Starter douglaskarr

    (@douglaskarr)

    Whenever I actually type the_date, it actually displays. I’m not sure why… but it’s a pain in the butt! ??

    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…

    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')

    Thread Starter douglaskarr

    (@douglaskarr)

    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘If the post date is today’ is closed to new replies.