I've been playing around with wordpress 3 to replace blogger.com, which was getting worse and worse over the years. Wordpress turned out to be quite nice, I was positively surprised to see what a great thing it has evolved to.
It has extensive widget support as well. But when I was looking for a baby age counter, I found 2, neither one of which worked. I think it was caused by their age; I've found a reference to wordpress 2.3, and the code was also looking quite horribly written. I'm not a php developer myself, but having extensive experience with other platforms, I can cope with it, and just by looking at it I could tell it was Bad Code (tm).
So I decided to write one. PHP didn't seem too hard. I've started off by googling for "wordpress widget tutorial", and found this great tutorial by Jesse Altman. It was basically a skeleton HelloWorld widget, well-written, well-explained. Without much further ado (except the PHP reference doc), I was able to create a baby counter widget.
It's a single .php file; just drop it into the wp-content/plugins directory of your wordpress (or use the admin interface to install it directly).
After activating, you can use the "Count all" widget under the 'Appearance' menu.
The values are self-explaining, but for reference:
- Title is the widget's title. It can contain HTML; its value is simply embedded into the resulting HTML page.
- Content is the widget content field. It uses the DateInterval::format function to format the field contents. You can use any field specifiers from that function. Its contents are also embedded into the resulting HTML page, so over the %-tags, you are free to use any HTML you want.
- Date specifies the date we should count distance from. Since this plugin simply takes the difference between 'now' and the specified date, it can be used for counting down (for dates in the future), or counting up (for dates in the past). It's all up to you.
This plugin needs Wordpress 2.8+ (tested to work on 2.8.4 and 3.0), and PHP 5.3 (for the DateInterval class).