Oliver Ker Design

Hire Me

Textpattern Mobile Site on a Subdomain

If you have been following my previous textpattern mobile site versions you may be pleased to know that I have new and more solid method of creating a mobile site but on a subdomain, still using the same database.

Create sub domain

This must be on the same host to match the root folder. Either copy the files below to you sub domain or download my commented files and upload.

Here is what I did for the files on the subdomain

.htacess

depends on how your file was in the first place but mine was standard I turned on the rewritebase /

rewritebase /

All your images that you have uploaded or use will be on the original domain, so when you are on the subdomain all relative links won’t work due to them not being on the subdomain url. So I added a redirect line to grab the images from the main domain url

redirect /images/ http://www.mysite.com/images/ 

I assume this would work for files and css etc…

Index.php

I changed one line here on line 18 to define the txpath back to original site root overriding the config.php file txpath (see file).

mobile_device_detect.php

Add this file to both root folders, on the original domain and the sub domain.

(timthumb.php)

This was the pain in the arse one! I have tried the current timthumb.php file at darrenhoyt.com but did not work. For some reason had a different version (attached) running on oliverker.co.uk which has some different code around line 532 where I added the original domain and this seems to work.

I use timthumb to resize images and it is placed in my root web folder. When I use timthumb I use upm_image and usually which uses the site url set in the admin prefs, which leads me on to the next part…

Important

In the txp admin preferences DELETE the site url so it displays nothing. Textpattern auto defaults to the current domain url so if you browsing the sub domain it will use a relative link rather than linking back to the main website.

In Textpattern admin

I use a page template to determine the device/domain and then use forms to place the content in where needed. My form is much more complicated than this and yours will be too, but I have simplified it for you to use.

You will need

In the download files I have put a commented version of the code below

<?php
include('mobile_device_detect.php');
$mobile = mobile_device_detect(true,false,true,true,true,true,true,false,false);
?>
<!DOCTYPE HTML>
<html>
<txp:ied_if_domain domain="sub.domain.com"> 
<head>
<txp:output_form form="iphone-head" />
</head>
<body >
<txp:output_form form="iphone-body" />
</body>
<txp:else/>
<head>
<txp:output_form form="head" />
</head>
<body>
<?php if($mobile==true): ?>
<a class="trymobile" href="http://sub.domain.com">Try the mobile specific site?</a>
<?php endif; ?>
<txp:output_form form="body" />
</body>
</txp:ied_if_domain>
</html>

Let users choose

If your user needed to get back to the main website then it is probably a good idea to have a link on the mobile site somewhere that links back to the main website.

Only tested in 4.2.0

, , ,

Comments

  1. # Zander 57 days ago

    Yet another great mobile solution for my favourite CMS, cheers Oliver

  2. # Oliver Ker 57 days ago

    Cheers Zander – Check out TXP Mobile for more Textpattern Mobile goodness hopefully coming soon

  3. # Sev 54 days ago

    Hey Oliver,

    thanks for sharing this. Worked like a charm for me. I will be posting the site I’m working on later. Still have to finish some CSS adjustments for the mobile version.

    Every Textpattern user who wants to go mobile with his site will be very happy with your tutorial :)

    Sev

  4. # Sev 31 days ago

    THE tutorial on the net to go mobile with your Textpattern site.

    Here’s the website I’ve been working on: http://www.indiginox.com and the mobile version http://m.indiginox.com.

    Again, thanks Oliver!

  5. # 23 days ago

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

More posts

Archive