A few months ago I purchased horrel.mobi with the vague inclination of actually doing something with it like, you know, a mobile version of this site. I struggled a bit with how to do this since I was having a hard time trying to figure out how to serve a different page to the new domain from Textpattern. Then, along came the ied_if_domain plugin (original forum post) and my problem was solved. Interestingly, I also figured out another handy solution using SimplePie, but I’ll get to both of those solutions later.
Of course the day I finally getting around to implementing this is the day Apple introduces a new phone a real browser in it1. Damn! Well, this is definitely going to change things for the better and in time I hope more companies start packaging a decent browser with their phones. And that means, of course, that a having a separate “mobile only” version won’t be necessary. Or at least, won’t be as necessary. Admittedly, I’ve never been a huge proponent of a mobile only web, as vaguely alluded to before. I bought the mobi domain anyway because, well, I’m a bit of a geek and also to grab it before anyone else got their filthy hands on it.
That being said, I thought I’d share how I pulled this off since the mobile market isn’t going to change over night and there are probably some other good uses for either approach.
The ied_if_domain plugin approach
This is what I currently use for my Textpattern driven site. It assumes you know your way around Textpattern and know how to install plugins, modify pages and forms, fiddle with Textpattern tags, and the like2.
- First, I created my horrell.mobi domain as an alias to my main one, horrell.ca (here’s some instructions on how to do this at TextDrive, written by yours truly).
- Next, I installed and activated the plugin. You can find the plugin here and here
- And Finally, I modified a few of my existing page templates, specifically the default one and a custom one I created for the Contact page. At the top, I used a
<txp:ied_if_domain domain="horrell.mobi">conditional to generate my mobile only pages and then my regular page follows after the
<txp:else />statement. There’s an example of how to do this in the plugin help if this doesn’t make any sense.
So, what the plugin does is check to see if my page is being accessed by the mobi domain and, if so, produces a slimmer modified version of my main and contact pages. Pretty neat eh?
Now while working on this I had another idea. I remember thinking “How can I get content out of Textpattern into another site?” You see, I was thinking of having horrell.mobi as a completely separate domain, not an alias, and I was toying with the idea of using PHP to grab content directly from the Textpattern database. I wanted it separate to keep my Textpattern templates simple but, admittedly, messing around with PHP and MySQL didn’t seem like the best approach. Then it hit me: syndication! All I had to do was grab content from my site feed and use that and thus was borne the SimplePie approach.
The SimplePie approach
SimplePie is a nifty API for reading RSS and Atom feeds and with it you can grab whatever feed you like and incorporate it into your own site, or even create a whole new site with it. The upside to this approach is that it doesn’t matter what you use to manage your site, so if you don’t use Textpattern then you’ve got this as an option as well. Now, for my own site I use the ied_if_domain plugin approach, but here’s how you’d do it this way:
- Create your mobi domain (instructions on how to do this at TextDrive can be found here, also created/revised by yours truly)
- Download SimplePie here
- Install SimplePie in the web root of your mobi domain (at TextDrive that would be either
public_html). You can find installation instructions for how to do this here
- Now, create your PHP page template for your site using. An example of how to do this can be found here
And that’s it. There are obviously a lot more steps to it, but you get the basic idea. I’ve been experimenting with SimplePie a little and I created a Christopher Planet of sorts that pulls in feeds from all my sites and services. It’s a work-in-progress, but at least I’ve found a use for my Horrell.info domain.
1 And I have to say, I love that bloody phone. The interface is fantastic and it’s pretty much everything I wanted in a phone.
2 There are some handy SimplePie plugins available for users of Wordpress and MediaWiki as well for incorporating feeds, but I have no idea if there’s an ied_if_domain equivalent.