American in Spain

One Year Ago Widget

June 4, 2007

This blog, in its present form, turned one year old this past weekend. It was a solemn single-candle ceremony. To look back over the previous trip around the sun, I've added a new feature to the sidebar called "One Year Ago", which displays three posts from one year ago. It's kind of a hacked up version of the One Year Ago Wordpress Plugin using my famous Widgetize Anything plugin.

The code used inside the body of the widget is as follows:

$dateago = (date('Y') - 1) . date('-m-d'); global $wpdb; $entries = $wpdb->get_results("SELECT *     FROM $wpdb->posts     WHERE post_status = 'publish' and post_date >= '$dateago'     ORDER BY post_date asc limit 3"); if ($entries) {   echo '<ul id="oneYearAgo">';   foreach ($entries as $entry)   {     $post_date = date('F j, Y', strtotime($entry->post_date));     echo "<li><a href=\"" . get_permalink($entry->ID) .         "\" title=\"Posted on $post_date\"" .         " class=\"tooltipped\">$entry->post_title</a></li>";   }   echo '</ul>'; }

You are now free to reminisce to your heart's content.