New project adds iCal feed to WordPress 3


I’ve been working with well known LibDem blogger Mark Pack, whose day job is with PR company Mandate, to migrate the website of the Cancer Campaigning Group over to WordPress. It’s a fairly modest little site, and I was under orders to keep the design broadly as-was. But it’s got one specific feature I’m very excited about.
Nearly four years ago, I wrote about the increasing adoption of the iCal standard for calendar sharing. With Outlook 2007 set to embrace the format, I foresaw a rush of websites publishing event data in iCal feeds, allowing you to subscribe with a single click, and then see someone else’s dates alongside your own.
The, ahem, optimistic assessment would be that I was well ahead of the curve. Four years on, you’ll struggle to find many (mainstream) sites offering such feeds – although I’ve noticed a slight increase of late. The BBC, for example, had a feed of World Cup fixtures; the Arsenal site has a similar service for its new fixture lists, including the Reserves, Youth and Ladies teams. Why? Maybe it’s the growing prevalence of smartphones by Apple and Google, both of whom were quick to adopt the format.
And then suddenly, the opportunity presented itself to build an iCal-enabled site of my own. The Cancer Campaigning Group’s previous site had an ‘events’ section, although it wasn’t anything special. WordPress 3.0, released just over a month ago, includes the ability to create ‘custom post types’; and I only recently discovered its little-documented ‘add_feed’ function, introduced as far back as early 2007. A little jQuery on the front- and back-ends, and we had all the ingredients we’d need.
So I’ve written some code to create a custom post type called ‘Event’, and added it into the WP back-end interface. You enter event details just as you would enter a post or page, with a title, body text and optional excerpt. There’s a special ‘event type’ categorisation; and a pop-up date picker for simplicity and consistency.

Then to call the calendar into a page, you use a WordPress shortcode – [calendar]. You can also specify the range (past or future), and the view (simple text list or javascript-enabled grid), plus the ‘type’ (if you’re using them). This actually gives you remarkable flexibility, only some of which is obvious on the Cancer Campaigning Group site.
And of course – there’s the iCal feed. If you take the feed URL into your calendar app of choice, you should be able to subscribe to it. And then, as the site admin adds new events, these will simply appear alongside your own personal appointments.
It hasn’t been easy: and to be honest, I’m not entirely confident that we’ve captured and resolved all possible issues. The biggest problem has actually been with Google Calendar: Google caches the feeds for an indeterminate period, and there’s no apparent way to force a refresh. So if there’s an issue with your code, you may not realise for several hours; and it may take a further few hours for your fix to feed through. I’m also fairly sure that the code, as it currently stands, won’t scale too well.
So for now, I’m watching the Cancer Campaigning Group site to see what happens. If it goes OK, I’ve got a couple of much higher-profile clients waiting in the wings.