Friday, 5 September 2008

optimized for the iphone

Sandwiches and Apples is now optimized for the iPhone.

How I did it:

I was playing around with the browser detect featured here in an attempt to load a separate index and stylesheet for iPhones. But I couldn’t figure out a way to get WordPress to fully ignore index.php and use iphone.php as the index.

So I went with a separate theme. I downloaded Content Robot’s plugin for an iPhone theme which has two parts: a plugin to detect the iPhone browser (which looks almost exactly like Pump Interactive’s detect) and a new theme optimized for the iPhone.

Since I don’t want to use their theme, I created my own and uploaded it to my themes folder. Then I opened their plugin and changed the two lines in bold below to point to my theme rather than the iWPhone theme included with the plugin download.


function get_stylesheet($stylesheet) {
if($this->iphone){
return 'iphone-theme';
}else{
return $stylesheet;
}
}

function get_template($template) {
if($this->iphone){
return 'iphone-theme';
}else{
return $template;
}

All that’s left was to style my site for the iPhone. Works like a charm.

Share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Reddit
  • StumbleUpon
  • Technorati
  • Netvibes
  • Posterous
  • Tumblr
  • Twitter
  • email
Tags: