WordPress Plugin: Time Since
If you read Simon Willison’s Weblog, you’re probably familiar with his time_since() PHP function (which was actually written by his girlfriend). This allows him to display the time elapsed since an entry was published. I took this code almost verbatim and created my first WordPress plugin. Here it is:
Download and save the file above as time_since.php into your/wp-content/plugins directory. Then within WordPress, go to the Plugin’s section of your weblog admin and activate the Time Since plugin.
This plugin will wrap any date or time (the_date() or the_time()) with an anchor element containing the elapsed time since the entry was published as a title attribute. This allows a user to hover over a date or time and see the elapsed time.
Update: A few people have reported a problem with getting the exact elapsed time to calculate. I suspect this has something to do with a host server’s time (typically set to the local time) varying from the entry post’s time adjusted for the timezone. It works on this site since my host server’s time is the same as my weblog’s timezone adjustment configuration. I’ll have to find a fix soon. Just know that this is a known issue. Thanks to those who reported it.
May 25th, 2004 at 6:26 AM PDT
I had something similar to this several version ago. I’ve now implemented this sucker on my blog.
It does seem to come up with some strange numbers for new posts though (-1 year, 12 months)…
May 25th, 2004 at 2:02 PM PDT
Time Since implemented
Like Binary Bonsai, Ive added the time since plugin - wave your mouse over the post date and Itll tell you how long since that post. It does have an issue with very recent posts though, and its possibly a big waste of time but hey, if you can, then do.
May 25th, 2004 at 5:58 PM PDT
I implemented a Perl version on my blog. No problem whatsoever with new posts using this code.
May 25th, 2004 at 5:59 PM PDT
I forgot the link: http://urbanmainframe.com/folders/blog/20040217/page_1.htm…
May 26th, 2004 at 1:49 AM PDT
WordPress Plugin: Time Since
Rich Manalang’s first plugin display’s the time since the post was published as a title attribute.
May 26th, 2004 at 4:55 AM PDT
I am a perl coder (not a php coder) but this is really cool. In the original code (if I read it correctly), it was possible to pass a time (whereas this excellent plugin takes the time from the post). Would it be possible to keep both options available so that the plugin could be used outside the loop as well. I have hacked a variant so that I can put a ‘This blog created on 2003/02/01′ type phrase on the right menu where the date has a ‘time since’ mouse-over. Unfortunately I don’t have the skills (yet) to merge this back into your plugin…..
(And I can’t show the results yet because they are on my test server not the production blog.)
May 26th, 2004 at 5:33 AM PDT
[...] 49637); Filed under: WordPress Plugins | 11:33 pm {} Rich Manalang’s first plugin display’s the time since the post was published as a title attri [...]
May 27th, 2004 at 5:17 PM PDT
Very nice. Perhaps, you can extend it to allow the use of the tag to show time since instead of the post time.
P.S.
Your site looks really odd in Safari. The sidebar appears in the middle of the page and there is a lot of white space before the comments.
May 27th, 2004 at 6:43 PM PDT
Alex, thanks for the heads up on Safari. Regarding the plugin, I’ll add another function that will allow you to do this.
May 29th, 2004 at 6:42 PM PDT
Rich, everything look great in Safari now
July 11th, 2004 at 2:01 PM PDT
Unless I’m missing something, I’ve found an issue with your plugin. If the_date() or the_time() use the before and after arguments in the function, like say an
set of tags, it breaks the validity of the XHTML. I tried making a quick workaround, but kinda got bogged down. If you wouldn’t mind, I’d be happy to use the plugin if it kept the code valid.
July 24th, 2004 at 8:12 PM PDT
Do you have this installed on your site? Because when I hover over your post time nothing shows up.
July 24th, 2004 at 8:23 PM PDT
Ryan, I turned it off a few days ago (debugging a problem)… it’s back on now.
July 25th, 2004 at 2:07 PM PDT
Thanks! Now I know it’s not my PC, I just didnt install it right.
It’s a really cool plugin.
July 25th, 2004 at 2:15 PM PDT
So how would I install this? I just save the txt file as a php file, put it in my plugins folder and activate it?
July 25th, 2004 at 3:02 PM PDT
Ryan, yep… just save as a php file then activate.
August 1st, 2004 at 9:49 PM PDT
That GReAT Plugin
Thanks
August 4th, 2004 at 4:11 AM PDT
Awesome plugin. Danke!
August 5th, 2004 at 8:35 PM PDT
[...] to the post date you can see the time since that post… kinda cool! Did this with theTime Since Plugin Comments » [...]
September 1st, 2004 at 9:09 AM PDT
[...] ;ll probably use this one. Time Of Day – seems useful, although I’m tempted by Time Since which shows the time since the post was published, 3 days for exam [...]
November 25th, 2004 at 11:51 PM PST
Rich, I think I’ve found a solution to the problem caused by the host server’s time differing from the local post time.
Edit line 23 as follows:
$today = time() + 60*60*x;
where x is the time difference between the host server and the entry post’s time in hours. I think there should be an easier way to do this by calculating x automatically using PHP, but unfortunately I’m not very familiar with PHP…please tell me if this is possible.
In any case the plugin now works fine on my blog.
cheers!
November 29th, 2004 at 2:13 PM PST
Thanks Gilbert. I’ll look into automating this based on the time offset property that’s stored in your WP options.
Rich
December 11th, 2004 at 4:57 PM PST
I’ve implemented this on my site as subtle text next to the date of the post. It’s a great plugin, but I am interested in a fix for the “-1 years, 12 months ago” post problem. When I try the
$today = time() + 60*60*x;code, it says my last post was 0 minutes ago, which is fine, but then all my previous posts seem to be off by the offset I enter there. It seems anything less than an hour is listed with the -1. It seems like a simple enough fix, but I’m not enough of a PHP jockey to alter it.Admittedly, this is a minor problem, but it sure would look nicer to see “12 minutes ago” rather than “-1 years, 12 months ago” for the first hour or so!
Thanks for the plugin.
January 9th, 2005 at 2:35 PM PST
-1 years, 12 months ago problem solved by correcting the “Times in the weblog should differ by” form field on the under General Options in the WP admin.
August 31st, 2005 at 2:42 PM PDT
hi.
just tried the different time_since plugins all along the web and yours is the only one working for me.
its such an brilliant idea of user-friendly displaying of time (etc) that i just “translated” the code into german (talkin’ about time and number and the thing with singular/plura is a bit more complicated in german, but nothing what 2 ifs couldn’t solve).
thanks for the plugin!
regards,
max
(mail me if you want to have the result - or have a watch at blog.REScrew.de -> it is under construction, but time_since should work)
September 23rd, 2005 at 7:01 AM PDT
@78.RES:
hi max, I would be interested in your german mod of the plugin.
Could you please send it to [toni] at [volloeko|de].
Thanks in advance!
February 2nd, 2006 at 7:43 PM PST
I like what you did with the design of your blog! Compliments. Regards, Albert.
August 25th, 2006 at 12:37 PM PDT
Hi, my “Time Offset” is set to +3, because my host time is GMT and I live in Bahrain, +3, so I get the “-1year 12 months” issue.
Any ideas on how to solve this?
September 22nd, 2006 at 10:46 PM PDT
with the “-1 year 12 months” issue… I tried to fix it by adding:
if ($since post_date);
so far, it works for me
September 22nd, 2006 at 10:49 PM PDT
opps.. sorry.. it seems the code dissapear..
try adding this
if ($since '.$original.'‘after this line:
$since = $today - strtotime($post->post_date);December 30th, 2006 at 1:54 AM PST
I have only been able to test this in the +GMT time zone, so I dont know if it works in the -GMT, but guess it does.
The first bit of code should be pasted right after where the array is declared.
$query = "SELECT option_value FROM wp_options WHERE option_name='gmt_offset'";
$result = mysql_query($query);
$gmt_offset_wp = mysql_result($result,0)*60*60;
$gmt_delta_today = tzdelta();
$today = time(); /* Current unix time */
$since = $today + $gmt_offset_wp - $gmt_delta_today - strtotime($post->post_date);
The second part should be pasted just before the ‘?>’ at the end of the plugin code
function tzdelta ( $iTime = 0 )
{
if ( 0 == $iTime ) { $iTime = time(); }
$ar = localtime ( $iTime );
$ar[5] += 1900; $ar[4]++;
$iTztime = gmmktime ( $ar[2], $ar[1], $ar[0], $ar[4], $ar[3], $ar[5], $ar[8] );
return ( $iTztime - $iTime );
}
How does it work?
WP seems to take the GMT time + your GMT offset and puts that as the date and time the entry was posted.
So, we need to get the
- GMT offset fromthe wp database (sql query in code)
- GMT time difference of where your server is (mine is in the US somewhere, and I am currently in Sri Lanka)
Then we use these 2 extra values to correct the value of today(), because that function gives you the local server time.
December 30th, 2006 at 1:57 AM PST
one thing. The quotes / speechmarks or whatever you call these must be replaced with those straight ones that are accepted by PhP. Sorry, but I am not sure how you call these things….
Let me know if this all works for you
February 10th, 2007 at 1:44 PM PST
Great
March 11th, 2007 at 8:33 PM PDT
This is my Digital Camera And Cell Phones Blog.
Full reviews of digital cameras and cellphones reviews… enjoy
June 17th, 2007 at 1:10 PM PDT
outpersonals.com
September 11th, 2007 at 12:25 AM PDT
i just installed this plugin on my blog and i love it! thank you!
September 15th, 2007 at 5:20 PM PDT
Kawa banga!
http://index.klassper.cn
MoNo
So so
September 18th, 2007 at 9:49 AM PDT
has anyone seen the new game copy pro software package they just came out with.
looks like it can copy ps2 games. has anyone used it before?
August 29th, 2008 at 6:52 AM PDT
klasfjkljasflkja skgj asdgas