WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to Display Today and Tomorrow Instead of Post Dates

How to Display Today and Tomorrow Instead of Post Dates

Viewing 3 replies - 1 through 3 (of 3 total)
  • You didn’t specify how yours isn’t working. One problem I can see is you’re telling it to display ‘Today’ or ‘Tomorrow’ based on || (or). So, if the eventtext is empty OR it’s in the category events OR the date’s match, echo ‘Today’. You want && (and) based on your criteria.

    Based on what you said, this is how I (think) I would do it.

    Basically, retrieve the desired meta key. If it returns, echo that. Otherwise, retrieve a list of the categories for the post and check to see if your category is in it. (get_the_category_list returns a string)

    If it’s in there, convert the post date to some standard format (see php.net/date). Do the same for today (just use date) and tomorrow (a combination of date and strtotime). If there’s a match in the strings, win! Otherwise, show the date.

    <?php
    $custom = get_post_meta($post->ID, 'myKey', 'true');
    if($custom) {
       echo($custom);
    } elseif(stristr(get_the_category_list(', '), 'events')) {
       $eventDate = get_the_date('Y-m-d');
       $today     = date('Y-m-d');
       $tomorrow  = date('Y-m-d', strtotime('+24 hours'));
       if($eventDate == $today) {
          $date = 'Today';
       } elseif($eventDate == $tomorrow) {
          $date = 'Tomorrow';
       } else {
          $date = $eventDate;
       }
       echo($date);
    }

    Thanks for your help! I am going to try using your set-up and will keep working on it.

    Thanks for your help! I just tried the code and it seems to be working perfectly!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Display Today and Tomorrow Instead of Post Dates’ is closed to new replies.