If..Else Log

New release of Time of Day plugin

A new version of the Time of Day WP plugin has been released for WordPress 1.5. The most important change to this release is that no plugin specific changes need to be made to your index.php file.

That is, instead of the ugly call to the time_of_day function:
<?php time_of_day(abs(strtotime($post->post_date)));?>
you should now use the standard WP the_time function call:
<?php the_time(); ?>

This is now possible due to the addition of the WP filter hook for the_time in WP 1.5. This means plugin (de)activation/implementation is now a one click procedure from within WP plugin screen. Unfortunately, WP 1.2 users will need to continue to use the older plugin.

-30-

68 Responses to “New release of Time of Day plugin”

  1. Gravatar Andre

    Mmh, it always returns “in the wee hours” regardless which case (?)

  2. Gravatar Andre

    my fault, i didn’t change <?php the_time(‘F jS, Y’) ?> into <?php the_time() ?> within the index.php of the default theme

  3. Gravatar Mike

    Is there a way to have the date show with every post in 1.5 (using Kubrick/default)?
    after removing the arguments in the call to the_time() it works, but I lose the display of the date. I can add a call to the_date() but then it only shows for the most recent post of the day.

  4. Gravatar Paula O.

    I admit. I am not a .php person.

    How do I take the text and make it into the file? Or do I need to drop the text into an already existing one? /blog/index.php?

  5. Gravatar If Else

    Paula,

    You need to download the plugin file and save it as timeofday.php. You then need to transfer this to your WP plugin directory i.e. http://paulaoffutt.com/blog/wp-content/plugins/

    After the plugin is transferred, you’ll need to login to WP, head on over to the plugin tab and activate the Time Of Day plugin.

    Mike,

    I’ll look into that issue this weekend. I didn’t do any special configuration on my theme but I never had time to check how it worked in Kubrick.

  6. Gravatar Mike

    Cool, I played with it a little bit but couldn’t figure it out.

  7. Gravatar Paula O.

    Thanks. I figured it out an hour or so later, but forgot to update here. sometimes I am so duh.

    Which leads me to the next question:
    if I go to a month archive via the main page, the top of it says ‘Archive for 2-7pm and getting warmed up’ (which is what I put in for 2-7pm). If I look at the manage>posts, all the information in the ‘when’ column says ’2-7pm and getting warmed up’.

    Whatever have I done wrong? I use the ‘Quentin’ theme, btw.

  8. Gravatar If Else

    Mike,
    I guess the easiest way is to use the old version of the theme and manually make a seperate call for the time of day
    i.e. add the following to your index.php at the point where you want the time of day.

    <?php time_of_day(abs(strtotime($post->post_date)));?>

  9. Gravatar If Else

    Paula,

    I think you problem is similar to the issue that mike posted about earlier. If you open up the theme’s index.php and change the line <?php the_time(’F jS, Y’) ?> into <?php the_time() ?>, then it should work.

  10. Gravatar Dan

    Hi,

    Noticed something very odd after installing this otherwise-great plugin. When I go to my “Manage” tab in the admin interface, and look at the “When” field for each post (that is, when the post was published), *every single one* has “in the early evening” written there, even though this is not true. In any case, I don’t need to have the plugin working in the admin screen – just on the blog. How can I fix this?

  11. Gravatar If Else

    When I go to my “Manage” tab in the admin interface… every single one* has “in the early evening” written there, even though this is not true.

    Wow, you’re right. I’d never even noticed that. I’ll have a look at it this weekend.

  12. Gravatar Phu

    Dan,
    I’ve updated the code to fix the issue in the WP admin interface. What was happening was that WP was adding a br tag which confused the PHP time parser.

  13. Gravatar Verit

    Hi Dan,

    I from Brazil and I’ve translated your plugin to brazilian portuguese. But, I use another plugin called CG-Archives by Year and yours make it desapear. Why? Could I use both plugin? How?

    Thanks.

  14. Gravatar N. A. Hilal

    Thank you!
    I use WP 1.5 and the old version of the theme and manually make a seperate call for the time of day to get format like this “March 28th, 2005, early evening”

  15. Gravatar Chuck

    I’m using the updated code found at http://www.ifelse.co.uk/code/timeofday.php. I’ve saved it as timeofday.php and ftp’d it to my WP plugin directory. When I go to my WP admin interface and access the “Plugins” tab, the Time of Day plugin does not appear as one of my plugins available for activation. I can see the timeofday.php file in the directory, but the plugin never appears in the WP Admin interface.

  16. Gravatar N. A. Hilal

    i have problem:
    my server time is set to UTC -1, how to get timeofday set to UTC+7.
    thx!

  17. Gravatar Marko

    Hi, I had the same ‘problem’ Mike had with this plugin, and I decided to just change the source to display the date too. All you have to do is to replace the return statement with the following line:
    return date('F jS, Y', $pdate) .', ' . $tod;
    (Change to date/time format to suit your needs)
    And don’t forget to change the call to the_time in the index.php of your template to something containing all needed information. (the default settings for the_time in the admin interface only print the time and no date, so php assumes that the date is the current day/month/year is today. Best is propably to change it to
    the_time('r')
    which will generate an RFC 2822 compliant string containing all information needed.
    To see this in action go to locher.at/marko (site is in German mostly), post me a message if you have further questions!
    Greets, Marko

  18. Gravatar Giocolando » Giocolando fai da te. Atto I

    [...] ratta semplicemente della combinazione di due plugin già esistenti: dunstant_time_since e time_of_day, ovviamente localizzati in italiano (e adattati al fat [...]

  19. Gravatar the country girl

    I had the same problem chuck did. I saved the timeofday.php file, uploaded it to my /wp-content/plugins/ folder, logged into wp, but it doesn’t show up under the plugins at all. I tried several times but no go. This is wp 1.5 any suggestions?

  20. Gravatar Allen

    Thanks for the cool plugin Phu, and thanks Marko for the date fix! :)

  21. Gravatar KosherJava

    I ran into the situation that Marko mentioned in post #17 when coding the Hebrew Date plugin that displays Hebrew Jewish dates. In his post he mentioned changing the template to avoid displaying the time as todays date. Not wanting to force the user to change themes, I coded a little hack that checks the $content for a ‘:’ and if there is a ‘:’ and no ‘,’ I am assuming it is purely a time and returning the time as is with no formatting. An other issue I had was that the the_time filter hook did not work on commnet post dates. I found what seems to be an undocumented hook get_comment_date at http://codex.wordpress.org/User:Skippy/Plugin_Hooks and when I also added this hook to my plugin, the code was called for comment date/time as well.

  22. Gravatar Poonam

    I am having the same trouble as country girl as it doesn’t show up in my plugins. i created a new php, copied and pasted, and still it doesn’t show up. Any help on why that happens?

  23. Gravatar Lefebvre

    The portuguese version is avaible here: http://www.saboya.org/?p=85. I have translated it.

  24. Gravatar PM

    just a quickie to say thanks. i installed this, just now… works perfectly! :)

    I do have a quick question – how can I get the date in there without messin’ up the time code? just curious…

  25. Gravatar PM

    Umm, nevermind.. I was able to just imput the date code seperately… I didn’t think that’d work but it did… simple.

    So, all taken care of… Thanks :)

  26. Gravatar Chris

    nice job… thanks

  27. Gravatar warmac

    am i on drugs or do i not see a download link to the timeofday.php plug in ?

    the one that exist doesn’t work, it seems to show the code all junked together is that the plugin file ?

    using the lastest WP version

  28. Gravatar warmac

    is this what i use as the plugin ?

    Dunstan’s Time of Day code that provides a friendlier display of post times. WP 1.2 users should use the older plugin. Version: 1.0.1 Author: Phu Ly & Dunstan Orchard & Michael Heilemann Author URI: http://www.ifelse.co.uk */ function time_of_day($content) { //$pdate = strtotime($content); $pdate = strtotime(str_replace(”
    “,”",$content)); //WP-Admin adds a break tag for display purposes which we have to strip out. $hour=date(‘H’,$pdate); switch($hour) { case 0: case 1: case 2: $tod = ‘in the wee hours’; break; case 3: case 4: case 5: case 6: $tod = ‘terribly early in the morning’; break; case 7: case 8: case 9: $tod = ‘in the early morning’; break; case 10: $tod = ‘mid-morning’; break; case 11: $tod = ‘just before lunchtime’; break; case 12: case 13: $tod = ‘around lunchtime’; break; case 14: $tod = ‘in the early afternoon’; break; case 15: case 16: $tod = ‘mid-afternoon’; break; case 17: $tod = ‘in the late afternoon’; break; case 18: case 19: $tod = ‘in the early evening’; break; case 20: case 21: $tod = ‘at around evening time’; break; case 22: $tod = ‘in the late evening’; break; case 23: $tod = ‘late at night’; break; default: $tod = ”; break; } return $tod; } add_filter(‘the_time’,'time_of_day’); ?>

  29. Gravatar warmac

    i got it to work, i downloaded the link uptop directly to the plugin, although would be better if it were in a more obvious place to download like standard plugins :) does it have to effect entire date ? I was wondering if we could still keep the date and use it or time only or does it overide all ?

  30. Gravatar Chris

    Here’s what I get when I installed the plugin:

    Parse error: parse error, unexpected T_FOR in /www/m/maltesenet/blog/htdocs/wp-content/plugins/timeofday.php on line 17

  31. Gravatar Chris

    Can someone be so kind as to tell me the URL of working code for this plugin and how to implement it on WP? My site http://blog.maltese.net uses many plugins, so I’m no stranger. This one just doesn’t work for me.

  32. Gravatar Chris

    OK, so I removed some whitespace from the script and it works. Now, I get: “in the wee hours, around lunchtime”. I know that to remove the constant, “in the wee hours”, I need to change the line into . When I do that, I lose the date. What is the right string to keep the date with the friendly “around lunchtime” time?

    TIA,
    Chris

  33. Gravatar Chris

    All fixed…

  34. Gravatar moley

    i had a prob. when i upload the timeofday.php into plugin folder, i can’t view my admin page or my blog page. Do you hv any idea what happen? I’m not too familiar with php.

  35. Gravatar RG

    Chris,

    I am getting the same parse error that you did (comment 30). I am not familiar with php. Please make a link to your edited script (comment 33) available.

  36. Gravatar DJ

    Hey, just wanted to post this in case anyone is having the same problems I was. I installed the plugin today, and I was trying to make the post time (right under the title of the post) show up in a certain way. I wanted it to show up in the post once as the time and once as the date. You may or may not know that the function the_date() can only be called once per day in WP 1.5.2. I wanted to have it say something like the following under my posts “Published around evening time on Sunday, October 2, 2005 in Randomness.” I tried just using the_time() for the date also (using the formatting ‘l, F j, Y’) but it would just post “in the wee hours” because the plugin automatically takes any instance of the_time and converts it to a clever statement like that. Then, I had an idea. I went into wp-includes/template-functions-general.php and searched for “the_time”. It just showed as:

    function the_time( $d = ” ) {
    echo apply_filters(‘the_time’, get_the_time( $d ), $d);
    }

    I duplicated it all and added 2 after the name of the function and in the filter so it looked like this:

    function the_time2( $d = ” ) {
    echo apply_filters(‘the_time2′, get_the_time( $d ), $d);
    }

    Then I went into my template and changed the first instance of the_time into the_time2. I also went into the plugin itself (timeofday.php) and changed

    add_filter(‘the_time’,'time_of_day’);

    to

    add_filter(‘the_time2′,’time_of_day’);

    It worked. Yay! This also eliminated the problem of the post times in the Dashboard–>Manage–>Posts area showing up as “in the wee hours” etc.
    I hope this helps out some people. This is a great plugin, thanks Mr. Ly!

  37. Gravatar Rusty

    Great plugin! – I of course had the desire like the rest to include the date with the reformatted timestamp. I was in the middle of implementing DJ’s great fix when I realized that there is already a “the_date” php function in WordPress. It is located immediately above the “the_time” function in wp-includes/template-functions-general.php. So all I did was insert , in the appropriate spot in my index.php and viola! Seems to work like a charm. Thanks for the plugin Mr. Ly, and thanks to DJ for making me think about it a little.

  38. Gravatar Shuai King

    Hello! Great plugin, but I would like to have on index.php or home.php the “around lunchtime” or whatever but on single.php the exact time.
    Thank you!

    Shuai King

  39. Gravatar Kunal Goel

    DJ’s fix is kinda complex and I get a parse error when I implement it.
    Is there any easier way to get the date in each post?

  40. Gravatar DJ

    Rusty- I was already using the_date on the page for something else, so that wasn’t feasible either. Glad I could help though. :)

  41. Gravatar David Carrington

    I’ve always like this plugin, even though I haven’t used WordPress for a long time. It’s almost strange that Drupal (well-known for being very too flexible) can’t make this work as a plugin (module). In the end, I’ve resulted to placing the code into my theme file.

  42. Gravatar Joe

    Hi,
    Is there a way to get the date / time and the time of day too like :
    December 19, lunch time
    Is that possible? Do I have to edit some code or go to the old version? Thanks

  43. Gravatar DJ LoBraico

    @Joe:
    Yeah, that’s definitely possible, I’ll check it out when I get home from school.

  44. Gravatar Joe

    O.K so it is possible…

  45. Gravatar Joe

    O.K,
    But how do you do that? Thanks

  46. Gravatar J.

    Hi,
    ist there a version for WP2.0 available? It does not work when activating the plugin only. I would have to adjust the index.php
    but than the date is missing… Well, that’s just a matter of try and error I guess.
    Forgive me, I’m new to PHP…
    J.

  47. Gravatar Joe

    Any One ? How to get the Date + / Time to display with the time of day text…

  48. Gravatar Joe

    Hmm, little error in my theme I have the time code in it displaying the date and then displays the time, but because of that I get : “at around evening time on in the wee hours” and so I figured if someone told me how to disable it from using the time and then I could. Use the code to add it (what the old version uses) into the title and it would display only after someone highlights the text. Thanks..

  49. Gravatar Joe

    Yeah me again got every thing set up, but all I need help on is how to get the plugin to use got_the_time (or what ever it is ) not the_time and then all be all set. Thanks…

  50. Gravatar Rusty

    Joe:
    See post 36 and 37 above.

  51. Gravatar Joe

    Thank’s Rusty ! I was not sure if it would work on WP 2.0m but it did. So thanks again…

  52. Gravatar stashuk

    Using “the_date” along with “the_time” does yield the proper result, but only for the first post on a given day. The day’s first post displays as:
    “post on Thursday, mid-morning”

    while subsequent posts on the same day display as:
    “posted on , around lunchtime”.

    Does anyone have a fix for this?

  53. Gravatar Ken

    Really cool,thank you

  54. Gravatar tnchick

    stashuk:

    Go to your wp-includes/template-functions-general.php

    Near the bottom find

    function the_time( $d = ‘’ ) {
    echo apply_filters(’the_time′, get_the_time( $d ), $d);
    }

    Under it add:

    function the_time2( $d = ‘’ ) {
    echo apply_filters(’the_time2′, get_the_time( $d ), $d);
    }

    Then, go into your theme and add:

    php the_time2(‘F j, Y’) php the_time()

    For an output like:

    April 7, 2006 really late at night

  55. Gravatar tnchick

    P.S. stashuk:

    Dont forget to put after it…. on both the time2 and the time

    if you really need any more help you can visit my site to contact me and i’ll email you the code.

  56. Gravatar Kakofon

    [...] I have spent too much time tinkering with this website today… But then again, I’ve been adding a lot of old stuff as well as pillaging newsstories related to yours truly from online papers. Techno-wise, the search function now searches in pages as well as posts thanks to David B. Nagle’s handy little wordpress plugin. And the timestamps on my posts are now a little more relaxed – just the way I like’em. Brilliant plugin by Phu Ly. [...]

  57. Gravatar Sorin

    Thanks to David Carrington!
    I like custom quick tags plug-in for cutenews script.

  58. Gravatar Sarah

    Have successfully installed and activated the time of day plug in, which for this newbie is a tremendous accomplishment, but…… I can’t access it when I am making a post, the time just comes up automaically. IS there anyway to make it so I can enter the “terribly early in the morning”? And finally the grammer is a bit off….
    It says “Loewen wrote this at in the late afternoon” Is there an easy way to correct this?

  59. Gravatar Inscrições » Mudanças

    [...] Time of day [...]

  60. Gravatar Maurice

    Can anyone give me ideas , i might get free time in the future and want to give it for wordpress …
    any idea ?
    i want idea from simple thing to mid … 1-2 hours –> 8-10 hours .
    post your ideas…

  61. Gravatar Saul

    Does anyone know the name of the wordpress plugin that creates a list of your posts in a category instead of just displaying them one after the other? I want it so that when someone clicks on a category they just get a list of posts from that category.

    I'm sure Ive seen one…and sifting through the WP site is a nightmare

  62. Gravatar Kleine Tigermaus

    Hello, I´m a girl from germany – sorry for my bad english.
    I have the plugin “time of day” and I want to use it at the posts and the comments. But I don´t know, what I must change that it work.

    Please, can you help me? My wordpress version is the 2.0.5.

    Thank you.

  63. Gravatar Tammy

    Great plug-in. :) But for some reason it has all my posts starting with ‘wee hours of the morning’. How can i fix this..? thanks. :)

  64. Gravatar CIO Jerry

    My blog runs wordpress.org 2.0.7. I just installed your plug-in today, thinking it’d be cool to have it. Unfortunately, once activated, the page shows ‘wee hours around lunch time’ instead of ‘January 17, 2007 wee hours’. I guess the plugin somehow confused about the DATE field and replaced it too. Any chance to get a fix/upgrade any time soon?
    From the comments above me, the release 1.0.1 was targeted for wordpress.org 1.5 release :(

  65. Gravatar Dan

    the month at the title of my archive page shows as “In Late Afternoon” etc, and doesnt show the month. pls help!

  66. Gravatar Thibaud

    Very good plugin: simple and efficient!

  67. Gravatar splashmilk

    CIO Jerry,

    For WordPress that runs on Ver 2.0.7, I’ve tried going to folder wp-includes/general-templates.php

    Try look for

    function the_time( $d = ‘’ ) {
    echo apply_filters(’the_time’, get_the_time( $d ), $d);
    }

    Duplicate this statement and paste just under it, then modify a little bit as

    function the_time2( $d = ‘’ ) {
    echo apply_filters(’the_time2’, get_the_time( $d ), $d);
    }

    Take note on both the “the_time2″ i’ve modified.

    Then go to open your timeofday.php at plugins folder. At the very end of the code. Modify the code from

    add_filter(’the_time’,’time_of_day’);

    to

    add_filter(’the_time2’,’time_of_day’);

    Last but not least, you need to go to your index.php in your template folder.

    And change the code

    ,

    into

    ,

    Walah! And the plugin ROX!