PHPCMS搭建wap手机网站 PHPCMS搭建PC端网站比较方便,但是在wap手机端方面却不怎么实用,而且自带的手机建站感觉不是很好,而且模版不好控制,现在对其进行修改,手机建站个人感觉比较方便 首先在phpcms/libs/functions/extention.func.php里面写入判断手机访
PHPCMS搭建wap手机网站
PHPCMS搭建PC端网站比较方便,但是在wap手机端方面却不怎么实用,而且自带的手机建站感觉不是很好,而且模版不好控制,现在对其进行修改,手机建站个人感觉比较方便
首先在phpcms/libs/functions/extention.func.php里面写入判断手机访问的自定义函数
<span style="color: #000000;">php </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * extention.func.php 用户自定义函数库 * * @copyright (C) 2005-2010 PHPCMS * @license * @lastmodify 2010-10-27 </span><span style="color: #008000;">*/</span> <span style="color: #008000;">//</span><span style="color: #008000;">判断是否手机访问</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> check_wap() { </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_VIA'])) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_X_NOKIA_CONNECTION_MODE'])) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_X_UP_CALLING_LINE_ID'])) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">strpos</span>(<span style="color: #008080;">strtoupper</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_ACCEPT']), "VND.WAP.WML") > 0<span style="color: #000000;">) { </span><span style="color: #008000;">//</span><span style="color: #008000;"> Check whether the browser/gateway says it accepts WML.</span> <span style="color: #800080;">$br</span> = "WML"<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #800080;">$browser</span> = <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_USER_AGENT']) ? <span style="color: #008080;">trim</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_USER_AGENT']) : ''<span style="color: #000000;">; </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$browser</span>)) <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">; </span><span style="color: #800080;">$clientkeywords</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>'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'<span style="color: #000000;"> ); </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">preg_match</span>("/(" . <span style="color: #008080;">implode</span>('|', <span style="color: #800080;">$clientkeywords</span>) . ")/i", <span style="color: #800080;">$browser</span>) && <span style="color: #008080;">strpos</span>(<span style="color: #800080;">$browser</span>, 'ipad') === <span style="color: #0000ff;">false</span><span style="color: #000000;">) { </span><span style="color: #800080;">$br</span> = "WML"<span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #【本文来自鸿网互联 (http://www.68idc.cn)】800080;">$br</span> = "HTML"<span style="color: #000000;">; } } </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$br</span> == "WML"<span style="color: #000000;">) { </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">TRUE</span><span style="color: #000000;">; } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">FALSE</span><span style="color: #000000;">; } } </span>?><br><br><br>然后在phpcms/templates/default模版文件夹里建立一个文件夹存放手机站的模版<br>我建立一个叫mobile的文件夹<br><br>然后修改
phpcms/templates/modules/content/index.php文件<br><br>麻烦点,分别在频道页,列表页,内容页加载模版时进行判断<br>比如:
<span style="color: #0000ff;">if</span><span style="color: #000000;"> (check_wap()) { </span><span style="color: #0000ff;">include</span> template('mobile', <span style="color: #800080;">$template</span><span style="color: #000000;">); } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span> <span style="color: #0000ff;">include</span> template('content', <span style="color: #800080;">$template</span><span style="color: #000000;">); }<br>这样当用手机访问时会加载mobile文件夹里面的模版,mobile文件夹里面的模版名字要跟PC端的一样。<br><br>当然,在生成静态页面时会出现问题,目前解决的办法是手机端用动态,<br>调用数据时可以这样</span>
<a href="index.php?m=content&c=index&a=show&catid=25&id={$r['id']}">
毕竟手机端的栏目不是很多
<span style="color: #000000;"><br /><br /></span>