Speed Project: Time Since Last Post

Speed Projects are a wonderful concept, that I stumbled across through FAT (Free Art & Technology). I've been thinking about writing a WordPress plugin for a while to motivate myself and to show site visitors, that my blogs are active.

Turns out, it only took me 25 minutes to produce a really tiny solution, that displays a human readable time since the last blog post was published. The credit is not really with me, but with the great documentation and pre-built WordPress functions.

It was amazingly easy to build a quick prototype, that I could put live right away. I'll spend some more time on it and make it more configurable, because I also want to use it on my German blog. Here's the code so far:

 Plugin Name: Time Since Last Post
 Plugin URI: @TODO:
 Description: Displays time passed since the last post was published
 Author: Jonathan M. Hethey
 Version: 0.1
 Author URI: http://jonathanmh.com
global $wp_version;
if((float)$wp_version &gt;= 2.8){
 class LastPost extends WP_Widget {

 function LastPost() {
 'Time Since Last Post Widget',
 'description' =&gt; 'Display the time passed since the last published post in a widget area'
function get_last() {
 $options = array(
 'numberposts' =&gt; 1,
 'orderby' =&gt; 'post_date',
 'order' =&gt; 'DESC',
 'post_status' =&gt; 'publish'
 $lastPost = wp_get_recent_posts($options);
 return $lastPost[0];
function widget($args, $instance){
 extract($args, EXTR_SKIP);
 echo $before_widget;
 $lastPost = $this-&gt;get_last();
 $lastPostUnix = strtotime($lastPost['post_date_gmt'].' GMT');
 $diff = human_time_diff( $lastPostUnix, current_time('timestamp') );
 echo 'last post: ' . $diff . ' ago';
 echo $after_widget;
add_action('widgets_init', 'lastPostInit');
function lastPostInit(){
} // end of compatability check
Tagged with: #plugin #time since last post #WordPress

Thank you for reading! If you have any comments, additions or questions, please tweet or toot them at me!