1

Topic: mobile version

I'm not a programmer and I don't know how to create a plugin... but I played a little bit with this script that generates a mobile version for small websites.
All you have to do is to download jquerymobile from http://jquerymobile.com/ and create a page with the following script:


<?php
$omit_pages = array('gallery', 'other-page');
?>
<?php 
    $www = array('www.');
    $no_www = array('');
    $output = str_replace($www, $no_www, $_SERVER['HTTP_HOST']);
?>

<!DOCTYPE html> 
<html> 
<head> 
    <title><?php echo $output; ?> - mobile version</title> 
    <meta charset="utf-8" /> 
    <link rel="stylesheet" href="<?php echo URL_PUBLIC; ?>public/jquery.mobile/jquery.mobile-1.0a1.min.css" />
    <script src="<?php echo URL_PUBLIC; ?>public/jquery.mobile/jquery-1.4.3.min.js"></script>
    <script src="<?php echo URL_PUBLIC; ?>public/jquery.mobile/jquery.mobile-1.0a1.min.js"></script>
    <?php echo "<link rel=\"canonical\" href=\"" . URL_PUBLIC . "\" />"; ?>

</head> 
<body> 

<div data-role="page" data-theme="a" id="home">
    <br /><center><?php echo $output; ?> - mobile version</center>
    
    <div data-role="content">
        <ul data-role="listview" data-inset="true" data-theme="a">
            <li><a href="#<?php echo $this->find('/')->title(); ?>" rel="external" data-transition="slide"><?php echo $this->find('/')->title(); ?></a></li>

            <?php
foreach($this->find('/')->children() as $page)
{
    $page_children = $page->children();

if (in_array($page->slug, $omit_pages)) {
    continue;
}

    if( count($page_children) > 0 )
    {
        echo '<li data-theme="c" data-icon="arrow-d"><a href="#">'.$page->title().'</a></li>';
    }
    else
    {
        echo '<li data-theme="c"><a href="#'.$page->slug.'" rel="external" data-transition="slide">'.$page->title().'</a></li>';
    }

    if( count($page_children) > 0 )
    {
        foreach( $page_children as $subpage )
        { 
            echo '<li class="ui-li ui-btn ui-btn-icon-right ui-btn-up-c" data-role="button">&nbsp;&nbsp;&nbsp;&nbsp;<a href="#'.$subpage->slug.'" rel="external" data-transition="slide">'.$subpage->title.'</a></li>';

        }
    }
}
?>
        </ul>
    </div>

<center>
View in <b>Mobile</b> | <a href="/">Classic</a><br />
</center>

    <div data-role="footer">
        <p><center>&copy; <?php echo date('Y'); ?>  <?php echo $output; ?></center></p>
    </div><!-- footer -->
</div><!-- page home -->



<div data-role="page" id="<?php echo $this->find('/')->title(); ?>">
    <div data-role="header">
        <h1><?php echo $this->find('/')->title(); ?></h1>
    </div><!-- header inside -->
    <div data-role="content">    
        <p><?php echo $this->find('/')->content(); ?></p>
    </div><!-- content inside -->

<center>
View in <b>Mobile</b> | <?php echo $this->find('/')->link('Classic', 'rel="external" target="_blank"') ?><br />
</center>

       <div data-role="footer">
        <p><center>&copy; <?php echo date('Y'); ?> <?php echo $output; ?></center></p>
    </div><!-- footer inside -->
</div><!-- page inside -->



<?php foreach ($this->find('/')->children() as $pagechild): ?>
<?php if (in_array($pagechild->slug, $omit_pages)) {continue;}?>

<div data-role="page" id="<?php echo $pagechild->slug(); ?>">
    <div data-role="header">
        <h1><?php echo $pagechild->title(); ?></h1>
    </div><!-- header inside -->
    <div data-role="content">    
        <p><?php echo $pagechild->content(); ?></p>
    </div><!-- content inside -->

<center>
View in <b>Mobile</b> | <?php echo $pagechild->link('Classic', 'rel="external" target="_blank"') ?><br />
</center>

       <div data-role="footer">
        <p><center>&copy; <?php echo date('Y'); ?> <?php echo $output; ?></center></p>
    </div><!-- footer inside -->
</div><!-- page inside -->



<?php foreach ($this->find($pagechild->slug())->children() as $pagegrandchild) : ?>

<div data-role="page" id="<?php echo $pagegrandchild->slug(); ?>">
    <div data-role="header">
        <h1><?php echo $pagegrandchild->title(); ?></h1>
    </div><!-- header inside -->
    <div data-role="content">    
        <p><?php echo $pagegrandchild->content(); ?></p>
    </div><!-- content inside -->

<center>
View in <b>Mobile</b> | <?php echo $pagegrandchild->link('Classic', 'rel="external" target="_blank"') ?><br />
</center>

       <div data-role="footer">
        <p><center>&copy; <?php echo date('Y'); ?> <?php echo $output; ?></center></p>
    </div><!-- footer inside -->
</div><!-- page inside -->

<?php endforeach; ?>
<?php endforeach; ?>


</body>
<?php $this->includeSnippet('snippet-traffic'); ?>
</html>

Any suggestions or improvements are more then welcome.
Thanks!
N

Last edited by negru (2010-12-09 21:46)

Thumbs up

2

Re: mobile version

Thanks for this, negru. It looks like it could be quite a valuable resource. Sadly, I don't have the means to test it myself!

Two quick questions:

1. What is the "snippet-traffic" snippet called at the bottom of the page?

2. When you say "create a page", do you mean "create a layout"?

Assuming this works like it looks like it should wink it would make a great candidate for a Layout with Logic treatment.

3

Re: mobile version

Thanks David!
1) Please ignore that line, I forgot to remove it. "snippet-traffic" is for traffic analytics purpose.
2) Not layout, I use a simple hidden page

Last edited by negru (2010-12-09 22:42)

Thumbs up

Re: mobile version

Sweet! I like the idea.
I have tried it right away and this is what I get:

Project79 mobile

It's working, but needs some improvements. This would be a great plugin (I wanted to do something like that).

It just displays home page, rest is in classic mode. Probably needs some tweaking.
You can try it here: http://project79.net/mobile

Wolf CMS Paper Guy
Wolf CMS related blog / journal at Project 79 | Wolf CMS Docs

5

Re: mobile version

Thanks Jackie! Make sure you don't apply any layout to this page.
I'm sure that can be improved, let me know if you have any ideas wink

Thumbs up

Re: mobile version

From what I've read, it sounds like this needs to go into a smart Layout that checks if its a mobile browser or not. Still a good idea though! smile

Wonder if there are any tutorials out there on how to create a good mobile version of a site?

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

7

Re: mobile version

I don't have time to dive into this right now, but it looks really neat! I'll definitely check it out tomorrow... er... later today. tongue Something I've been working with is inline media queries from css3 for dynamic regeneration of pages' structure dependent upon the browser's viewing area. I got the idea from the less framework if you want to see how they work. I'm working to make my page layouts retrograde nicely into any resolution without losing their brand identity.

edit - I just wanted to also point you to one of my favorite online cell phone emulators in case you hadn't seen one yet. There are several out there now. big_smile

Last edited by qbass (2010-12-10 13:00)

It made me think about it.
It made me.
Think about it.

Thumbs up

8

Re: mobile version

Here is a screenshot from a website that has sub-pages:

mobile

Thumbs up

Re: mobile version

I'm considering using it to, looks very nice on mobile browsers judging from your image.

10

Re: mobile version

Is there anywhere currently on the wolfcms site that shows how to create a mobile version of the site?

Bah! Humbug!

Re: mobile version

@dover - Not really since we haven't looked at what actually IS a mobile version.

However, it really shouldn't be very difficult I suppose. You just create a Layout that looks good on mobile. If you want to auto-redirect people to the mobile version, I guess you'd have to do some sort of browser detection. I never looked into it myself simply due to a lack of time.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

12

Re: mobile version

Actually, I had an idea based on what you said. With most mobile sites they are operated on a subdomain, for example m.mydomain.com.

Now would the following work. If I created a subdomain of m. and installed wolfcms on the subdomain m.mydomain.com, would it be possible to use just the pages/content from the database on mydomain.com so that the content is the same on both and then just create a separate theme?

That would seem like a possibility of how to do it, but I've never been able to work out how to set it up in wolf as I don't understand the insides of wolf too well (and don't really want to look to hard).

It'd be nice to know as I want to create a few mobile versions.

Bah! Humbug!

13

Re: mobile version

Unless there's a way to dynamically change the theme from inside the current installation based on the browser detection result (and do some rewriting of the url would also be great)?

Bah! Humbug!

Re: mobile version

I don't think browser detection is the way to go at all, instead look at CSS3 Media Queries.
That is the true proper way of dealing with different UI's.

Last edited by Fortron (2011-01-06 19:08)

15

Re: mobile version

I've seen them before and thought it was a good move but read somewhere that sometimes they are not accurate. hmm Assuming that information was wrong, can css media query possibly handle a redirect?

I think I'd prefer my mobile site on a sub domain so I could layout the html differently if needed and then be able to use the content from the main websites database.

Bah! Humbug!

Re: mobile version

dover wrote:

I've seen them before and thought it was a good move but read somewhere that sometimes they are not accurate. hmm Assuming that information was wrong, can css media query possibly handle a redirect?

I think I'd prefer my mobile site on a sub domain so I could layout the html differently if needed and then be able to use the content from the main websites database.

CSS3 doesn't do redirects.

You can have multiple stylesheets for multple UI's and/or uses on different devices and systems without the need for a mobile version on a subdomain.
You can target what stylesheet is ment for what UI and its up to the UI to use it.
Use for instance CSS @media handheld to target handheld devices.

I would not advice using browser detection, not even as a last resort.
But if you insist in having it that way then browser detection is the only way.
In that case you could try WURFL

Last edited by Fortron (2011-01-07 15:56)

17

Re: mobile version

Just personal preference for me then I guess. I just much much prefer going to m.mysite.com to get to the mobile version which needs browser detection. I read there's a jquery one that works pretty well.

Can someone please answer re serving the content of the main site on a subdomain if possible?

Bah! Humbug!

Re: mobile version

dover wrote:

Can someone please answer re serving the content of the main site on a subdomain if possible?

If i'm not mistaken that should be only a matter of installing Wolf CMS on the subdomain
and using your existing database and config.php for getting the content.

19

Re: mobile version

I thought exactly that as well.. But then I thought, doesn't it defeat the point a bit as it'll call up all the same themes as well?

You'd pretty much get exactly the same site, just with two different sub domains.

I was wondering if it'd possibly be a fresh wolf install, and then create the themes and then modify a bit of code somewhere to call the pages from the first database or something like that.

Of course.. I'm only guessing. -sits down and waits for the wolf experts to correct me- big_smile

Last edited by dover (2011-01-06 20:49)

Bah! Humbug!

Re: mobile version

dover wrote:

I thought exactly that as well.. But then I thought, doesn't it defeat the point a bit as it'll call up all the same themes as well?

No, you just select a different layout/theme for the mobile version and your done.

Last edited by Fortron (2011-01-06 20:55)

21

Re: mobile version

Which if using the same database would change the layout for the original site as well. If you are accessing the same database with the same logins, as far as I'm aware, it won't matter which install of wolf you use to edit data, you'll be changing the same data.

I was under the impression if you just change the theme, you'll be changing it for both domains.

Bah! Humbug!

Re: mobile version

dover wrote:

Which if using the same database would change the layout for the original site as well. If you are accessing the same database with the same logins, as far as I'm aware, it won't matter which install of wolf you use to edit data, you'll be changing the same data.

I was under the impression if you just change the theme, you'll be changing it for both domains.

Yes you are right offcourse.
Makes me wonder if a plugin could handle subdomains.
Something like the multiple languages plugin, but then for subdomains.
Anyone?

Re: mobile version

Fortron wrote:

Makes me wonder if a plugin could handle subdomains.
Something like the multiple languages plugin, but then for subdomains.

I believe it could. (quite easily even)

There are several things going on here.. or rather questions that need to be answered:

1) What does the HTML+CSS look like for a good mobile site?

2) Is it enough to just use a different stylesheet? (I believe, probably not)

3) Is a subdomain like m.example.com a good idea? (I believe it is a good practice)

4) Do we auto-detect and auto-redirect mobile users to a mobile version of the site?

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

Re: mobile version

Well you could try the following possible solution. Untested though.
1. Create two snippets, one with your regular layout and another for the subdomain.
2. Create a new layout and add this:

<?php
if ( $_SERVER["HTTP_HOST"] == 'subdomain.foo.ltd' ) {
  $this->includeSnippet('mobilelayout');
} else {
  $this->includeSnippet('regularlayout');
}
?>

After that just assign the new layout to the Home page and it should work?

Last edited by Fortron (2011-01-07 09:09)

25

Re: mobile version

1) What does the HTML+CSS look like for a good mobile site?

The answer is simple. No really, the html and css should be simple to allow as many mobile devices as possible to view it big_smile

Basically people just want to get the content quickly (small download) and see it clearly (formatted for a smaller screen)

(**side note** iDevices are pretty cool in that you can change the look and feel of a site based on which way the device is rotated using css and possibly a small bit of js. You can also do a lot of advanced things on it you can't do on most phones)

2) Is it enough to just use a different stylesheet?

Absolutely not (imo). Otherwise I already would have used css media to define the different style sheets and be done with it (which I have thought about a fair bit). There are simply put, features on main sites you just don't want on a mobile device.

For really basic sites, media is fine. In fact it's probably great as it's simple to use/implement and and as the sites small anyway, download speeds aren't a problem. But for most sites I've found that at minimum, I want to change the layout for a site on a mobile device, which can't be done using just css.

The size of the website page really has to be cut down a lot to absolute bare minimum. If we just use a lot of conditionals (say using js or php for as an example" if ($media='handheld' {echo 'simple mobile title layout';} {echo 'screen title layout';}", then we are just adding more to the site rather than cutting it down.

Using a plugin, we should be able to set it up so that before it's even loaded much of the site it's check if we're on a device and redirected using one conditional check. I'm sorry if I haven't explained myself well btw.

3) Is a subdomain like m.example.com a good idea?

I've already indicated my preference but perhaps I should say why. For one it's nice to see just from the URL that I'm on a mobile version and m. seems pretty universal atm. There is also use of both m. AND touch. for those who like to cover all bases. See facebook for an example (m.facebook.com and touch.facebook.com).

I love that as an iPhone user as it gives me an advanced website as my phone can handle it, but then my girlfriend on an old nokia still gets a usable website.

I've found (genreally speaking) the convention is to have the URL as http://m.mainsite.com/en/page-slug

m - represents the device (if developed for, so can be m touch etc)
en - represents language shortcode (if multiple languages is available) (does the language plugin currently rewrite the URL that way?)

I think if we stick to that convention we'll also find SEO will be good.

4) Do we auto-detect and auto-redirect mobile users to a mobile version of the site?

When possible (ie when the device can handle our redirection method. eg. if we use js, when the device has js installed - which most do) I think we should. But on the same hand, we also need to be able to on the mobile version of the site, allow users the option to go back to the main site.

Not only do we need to be able to go back to the main site, but we technically should be able to make it so that if the user goes to the main site, when they next visit the site, it will automatically go back to the main site again, as we are developing for the end user after all.

I think this is easily achieved using cookies.


@Fortron You had me worried when you mentioned just installing it on a new subdomain and changed the themes. I thought for a second I just was not understanding basics of databases. In regards to your suggestion, I like it. I could see how that would work well and could be implemented into a plugin possibly (I don't particularly want my sub themes to be a snippet).

It's pretty much how I could see it working, and if you want to implement redirection, you'd need to code it yourself in the sub theme. That way, less bloat in the plugin and developers still can control how their site works.

Bah! Humbug!