Make A Mobile Site From An RSS Feed

Tom's picture

In my spare time I contribute to DCist, the Washington edition of the Gothamist blog network. Yesterday I got an email from a reader asking why our mobile version was so out-of-date — I hadn't realized it, but she was right: the mobile edition had fallen through the cracks as the network's configuration changed & grew.

So I took a stab at writing a general solution to the problem that could be used across the -ist sites, and was pleasantly surprised at how easy it turned out to be. You might find it useful, too.

The solution takes a full-text RSS feed and turns it into some parsimonious HTML that should be suitable for most mobiles. And it ought to work for any valid RSS feed. You can check out DCist's mobile feed here. Alternately, you can check out a mobile version of this blog here. If you'd like to try it on another blog, just enter its RSS feed in the field below and hit submit.



The script itself is pretty short, and is recreated behind the jump. It'll require that you install a copy of Magpie RSS in an appropriately-named subdirectory. And if you want to use caching — and I recommend that you do — you'll need to make sure that you have the PEAR::Cache package installed.

You can find the code after the jump, or simply download it here.

Of course, you'll need to instruct your mobile users to go to a different URL. Could that be done automatically instead? Stay tuned.


You must specify the URL of a valid RSS feed in the 'url' parameter of the querystring.

Where do you put the RSS url

Where do you put the RSS url within the acript at?

The URL is grabbed from a

The URL is grabbed from a GET parameter in the following line:

$rss_url = urldecode($_GET['rss']);

You could override that easily if you want to hardcode the URL.

Here's a nice set of

Here's a nice set of functions to detect mobile phones, as well as a separate & simple function to detect the iPhone specifically with php.

http://www.andymoore.info/php-to-detect-mobile-phones/

Cheers

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode>
  • Lines and paragraphs break automatically.
  • You may post block code using <blockcode [type="language"]>...</blockcode> tags. You may also post inline code using <code [type="language"]>...</code> tags.

More information about formatting options

Captcha
Are you a robot? We usually like robots, but not in our comments.