Home > CMS Tutorial > PHPCMS > body text

How to build a mobile site with phpcms

Release: 2019-10-30 17:38:59
Original
3969 people have browsed it

How to build a mobile site with phpcms

PHPCMS is more convenient to build a PC website, but it is not very practical for wap mobile phones. Moreover, the built-in mobile website building does not feel very good, and the template is difficult to control. Now it is To modify it,

first write the custom function to determine mobile phone access in phpcms/libs/functions/extention.func.php

<?php
/**
 *  extention.func.php 用户自定义函数库
 *
 * @copyright            (C) 2005-2010 PHPCMS
 * @license                
 * @lastmodify            2010-10-27
 */

//判断是否手机访问
function check_wap()
{
   
    if (isset($_SERVER[&#39;HTTP_VIA&#39;])) return true;
    if (isset($_SERVER[&#39;HTTP_X_NOKIA_CONNECTION_MODE&#39;])) return true;
    if (isset($_SERVER[&#39;HTTP_X_UP_CALLING_LINE_ID&#39;])) return true;
    if (strpos(strtoupper($_SERVER[&#39;HTTP_ACCEPT&#39;]), "VND.WAP.WML") > 0) {
        // Check whether the browser/gateway says it accepts WML.
        $br = "WML";
    } else {
        $browser = isset($_SERVER[&#39;HTTP_USER_AGENT&#39;]) ? trim($_SERVER[&#39;HTTP_USER_AGENT&#39;]) : &#39;&#39;;
        if (empty($browser)) return true;
        $clientkeywords = array(
            &#39;nokia&#39;, &#39;sony&#39;, &#39;ericsson&#39;, &#39;mot&#39;, &#39;samsung&#39;, &#39;htc&#39;, &#39;sgh&#39;, &#39;lg&#39;, &#39;sharp&#39;, &#39;sie-&#39;
        , &#39;philips&#39;, &#39;panasonic&#39;, &#39;alcatel&#39;, &#39;lenovo&#39;, &#39;iphone&#39;, &#39;ipod&#39;, &#39;blackberry&#39;, &#39;meizu&#39;,
            &#39;android&#39;, &#39;netfront&#39;, &#39;symbian&#39;, &#39;ucweb&#39;, &#39;windowsce&#39;, &#39;palm&#39;, &#39;operamini&#39;,
            &#39;operamobi&#39;, &#39;opera mobi&#39;, &#39;openwave&#39;, &#39;nexusone&#39;, &#39;cldc&#39;, &#39;midp&#39;, &#39;wap&#39;, &#39;mobile&#39;
        );
        if (preg_match("/(" . implode(&#39;|&#39;, $clientkeywords) . ")/i", $browser) && strpos($browser, &#39;ipad&#39;) === false) {
            $br = "WML";
        } else {
            $br = "HTML";
        }
    }
    if ($br == "WML") {
        return TRUE;
    } else {
        return FALSE;
    }
}
?>
Copy after login

and then in the phpcms/templates/default template folder Create a folder to store the template of the mobile site

Create a folder called mobile

Then modify the

phpcms/templates/modules/content/index.php file

Troublesome point, make a judgment when loading the template on the channel page, list page, and content page respectively

For example:

if (check_wap()) {
    include template(&#39;mobile&#39;, $template);
} else {
    include template(&#39;content&#39;, $template);
}
Copy after login

In this way, mobile will be loaded when accessed by mobile phone The templates in the folder and the template names in the mobile folder must be the same as those on the PC.

Of course, there will be problems when generating static pages. The current solution is to use dynamic ones on the mobile phone.

You can do this when calling data

?1<a href="index.php?m=content&c=index&a=show&catid=25&id={$r[&#39;id&#39;]}">
Copy after login

The above is the detailed content of How to build a mobile site with phpcms. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!