使用PHPCMS搭建wap手机网站

首先在phpcms/libs/functions/extention.func.php里面写入判断手机访问的自定义函数

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <?php /**  * extention.func.php 用户自定义函数库  *  * @copyright   (C) 2005-2010 PHPCMS  * @license     * @lastmodify   2010-10-27  */ //判断是否手机访问 function check_wap() {  if (isset($_SERVER['HTTP_VIA'])) return true;  if (isset($_SERVER['HTTP_X_NOKIA_CONNECTION_MODE'])) return true;  if (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])) return true;  if (strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML") > 0) {   // Check whether the browser/gateway says it accepts WML.   $br = "WML";  } else {   $browser = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : '';   if (empty($browser)) return true;   $clientkeywords = array(    'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-'   , 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',    'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini',    'operamobi', 'opera mobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile'   );   if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", $browser) && strpos($browser, 'ipad') === false) {    $br = "WML";   } else {    $br = "HTML";   }  }  if ($br == "WML") {   return TRUE;  } else {   return FALSE;  } } ?>

然后在phpcms/templates/default模版文件夹里建立一个文件夹存放手机站的模版

我建立一个叫mobile的文件夹

然后修改
phpcms/templates/modules/content/index.php文件

麻烦点,分别在频道页,列表页,内容页加载模版时进行判断
比如:

?
1 2 3 4 5   if (check_wap()) {  include template('mobile', $template); } else {  include template('content', $template); }

这样当用手机访问时会加载mobile文件夹里面的模版,mobile文件夹里面的模版名字要跟PC端的一样。
当然,在生成静态页面时会出现问题,目前解决的办法是手机端用动态,
调用数据时可以这样

?
1 <a href="index.php?m=content&c=index&a=show&catid=25&id={$r['id']}">

毕竟手机端的栏目不是很多。

相关文章

本教程操作系统:Windows10系统、phpcms 9版本、Dell G3电脑...
PHPcms访问特点:单一入口模式。无论访问任何一个模块或者功...
例如:{pc:contentaction="position"posid="...
首先,上图之中的红色框框是没有的,我们想要给他加上,当然...
头部<metaname="keywords"content="{$SEO...
做网站时用的到的简单的栏目导航()phpcms多个栏目catidin(9,...