After saying on my previous post about using Twitter and (maybe) a new design for Dazecoop, I needed to find a Wordpress Plugin to grab the RSS feed of my Twitter account, then display it nicely on my WP header.
Simple Twitter seemed to fit the bill nicely, and within about 40 seconds of installing it, my latest “tweet” was in my header for all to see - not only that but Simple Twitter includes a caching feature as not to bombard Twitter too much.
After installing it though, I was a little disappointed to see that it didn’t return how long ago my latest tweet was made. Booger! I had a quick look at the code and decided to hack-my-way in so grab this information…
Basically, within the function update_twitter_message(), I added in this code below line 141:
// ** modifications to show how long ago tweet was made
// ** quick & dirty hack - c'mon, its 1am!...
// ** accuracy all depends on cache time, i use re-cache every 15 mins
// ** by David Cooper - www.dazecoop.co.uk
$timenow = time();
$pubdate = strtotime(get_message_from_url($url, 'pubDate', 'item'));
$minutespast = round(($timenow - $pubdate) / 60);
$hourspast = round($minutespast / 60);
$dayspast = round($hourspast / 24);
if ($minutespast < 2) {
$returnTimepast = 'a few minutes ago';
} elseif ($minutespast < 55) {
$returnTimepast = 'roughly ' . $minutespast . ' minutes ago';
} elseif (($minutespast > 55) && ($minutespast < 110)) {
$returnTimepast = 'about an hour ago';
} elseif ($hourspast < 23) {
$returnTimepast = $hourspast . ' hours ago';
} elseif (($hourspast > 23) && ($hourspast < 47)) {
$returnTimepast = 'yesterday';
} else {
$returnTimepast = $dayspast . ' days ago';
}
$title = get_message_from_url($url) . ' <small>' . $returnTimepast . '</small>';
//$title = get_message_from_url($url);
// ** end modifications
The $title variable is the only thing that I’ve changed, original is:
$title = get_message_from_url($url);
And my version is now:
$title = get_message_from_url($url) . ' <small>' . $returnTimepast . '</small>';
Job done! And works wonders





3 Oct 2008 at 3:35 pm
Mate - there are a number of tools you can use to do this with no hacking. Ocaimh.ie (I think) has a twitter cache plugin - doesn’t display on the blog yet but does cache both sides of conversations in the dashborad. You could also Google for Twitter Tools from Alex King which WILL display.
