My first Wordpress plugin. You can see it in action right above this post under the header image. No, really. Hit refresh. It does exactly what you’d expect: Display a single, random post from your Wordpress database.

I added a bit of code around it to jazz it up, which I plan to incorporate into the 1.1 version, if anybody even shows an interest in the 1.0 version.

Revision 1.02: Removed a blank line that was causing RSS feeds to break.

Download wp-single-random-post.zip

README FILE:

=== Single Random Post ===
Contributors: dcostalis
Donate link: http://www.isthisablog.com/
Tags: random, posts
Requires at least: 2.0
Tested up to: 2.7.1
Stable tag: 1.02

This plugin will allow you to display a single post selected at random from your post database

== Description ==

This plugin will allow you to display a single post selected at random from your post database

There are no bells and no whistles.

== Installation ==

1. Upload `single-random-post.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the ‘Plugins’ menu in WordPress
3. Place `<?php single_random_post(); ?>` in your templates

== Frequently Asked Questions ==

= Why does this even exist? =

Because I had a use for it, and nobody else had made it yet

= Why doesn’t it do more? =

Because there are plenty of plugins that do a lot more, but none that do this little without editing
Download wp-single-random-post.zip

Tags: , ,

While modifying a plugin to work correctly in WP 2.5, I came across this code snippet.

I haven’t had to deal with it myself, but maybe someone else will find it useful, or hilarious as I did. Here’s the code to make timestamps WordPress friendly (apprently):

// Dealing with timestamps in WordPress is so fucking fucked.
$offset = (int) get_option('gmt_offset') * 60 * 60;
$this->post['post_date'] = gmdate('Y-m-d H:i:s', $this->published()
    + $offset);
$this->post['post_modified'] = gmdate('Y-m-d H:i:s',
    $this->updated() + $offset);
$this->post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $this->
     published());
$this->post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $this->
     updated());

Tags: , , ,