Wording based on time

Would you like to have a different saying below your post based on what time it was posted instead of (or in addition to) the date? A poster on the MT forums did, so I cooked up this little script yesterday.

<?
//set the beginning time for each time section - keep the quotes in there
$earlymorn = strtotime(”4:30am”);
$midmorn = strtotime(”9:00am”);
$lunch = strtotime(”11:30am”);
$afternoon = strtotime(”1:00pm”);
$evening = strtotime(”5:00pm”);
$bedtime = strtotime(”9:00pm”);

//This date format is for MT2.5 and above
$t = strtotime(”<$MTEntryDate format=”%X”$>”);

//Modify the messages as necessary - note that the middle of the night one should be in there twice.
if ($t <= $earlymorn) { echo “Past Your Bedtime”; }
elseif ($t <= $midmorn) { echo “Early Morning”; }
elseif ($t <= $lunch) { echo “Mid-Morning”; }
elseif ($t <= $afternoon) { echo “Lunch time”; }
elseif ($t <= $evening) { echo “Afternoon”; }
elseif ($t <= $bedtime) { echo “Evening”; }
else echo “Past your bedtime”;
?>

Enjoy! :)

11 Responses to “Wording based on time”

  1. kadyellebee Says:
    postings
    I’m doing some housekeeping on my desk, and had a few things that needed posting on several of my blogs

  2. Tudy Says:

    Maybe you could direct me to a php tutorial online somewhere? :-) Please.

  3. kristine Says:

    Our Resources page points to a few great PHP resources.
    And I made a post not too long ago with some more great starting-out links.
    Hope that helps! :)

  4. skits Says:

    This is awesome cool–thank you! One quick question…does your entire page have to utilize php to use this? (I’ve inserted the script into my MT template and I’m pretty sure I’ve done it correctly, but nothing shows up–do I have to put anything in the header?)

  5. maddy's rambles Says:
    Pastel Pastiche
    How I ended up using pastel colours in this “design” I do not know. I’m not really big on pastel

  6. maddy Says:

    This rocks, Kristine! Thank’s heaps. And Skits, your page will need to have the .php extension, or your server must parse html pages for php scripts. :)

  7. Nilesh Says:

    Neat!

    And in case you needed to know at what times you have blogged this month, you can have a look at my MTBlogTimes plugin (or here). Maybe this is a shameless plug, but worth a look at. :-)

  8. skits Says:

    Thanks, Maddy. I’m stilling the learning stages over here. :D

  9. maddy Says:

    Hey, mcroft just posted a way to do this with the MTMacros Plugin for those that don’t have php. It’s all in the link that Kristine referenced up there for the MT forums! :)

  10. J : Da Blog Says:
    PHP and more
    My page now has a .php extension. I’ve probably been living under a rock, but I had no idea you

  11. J : Da Blog Says:
    PHP and more
    My page now has a .php extension. I’ve probably been living under a rock, but I had no idea you