I’ve been wanting to add the little calendar graphics to my posts for a while now. If you’ve not seen them, they’re on the web version… click on over and take a look! I started with some graphics from another site, but decided that I wanted to spice it up a little bit. So, I wrote two classes for the date div and set the background image differently based on whether or not the post was written today.
Thanks to Michael H in the WordPress Support Forums, I finally got my statement correct! Here’s what I did. I have a background image set for the div class date:
>div class=”the_date”>
For today’s div, I set a different background image applied to a div class named the_date_today:
>div class=”the_date_today”>
Now that I’ve got those set, I need to write some code that adds the “_today” if the post was written today:
>div class=”the_date>?php $post_date = mysql2date(‘Ymd’, $post->post_date_gmt); if($post_date==gmdate(‘Ymd’)) { echo ‘_today’; } ?>”>
Here’s how this works:
- I set a variable called $post_date equal to the date of the post formatted as Ymd.
- I write an if statement so that if that variable equals today’s date (formatted as Ymd as well), I add “_today”
Voila! Now I have a calendar graphic that displays whether or not the post was written today! I just need to adjust for timezone and I’ll have it made!