首頁 > 後端開發 > php教程 > PHPCMS搭建wap手機網站

PHPCMS搭建wap手機網站

WBOY
發布: 2016-07-29 09:15:10
原創
935 人瀏覽過

PHPCMS搭建PC端網站比較方便,但是在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

<?<span>php

</span><span>/*</span><span>*

 *  extention.func.php 用户自定义函数库

 *

 * @copyright            (C) 2005-2010 PHPCMS

 * @license               

 * @lastmodify            2010-10-27

 </span><span>*/</span><span>//</span><span>判断是否手机访问</span><span>function</span><span> check_wap()

{

    

    </span><span>if</span> (<span>isset</span>(<span>$_SERVER</span>['HTTP_VIA'])) <span>return</span><span>true</span><span>;

    </span><span>if</span> (<span>isset</span>(<span>$_SERVER</span>['HTTP_X_NOKIA_CONNECTION_MODE'])) <span>return</span><span>true</span><span>;

    </span><span>if</span> (<span>isset</span>(<span>$_SERVER</span>['HTTP_X_UP_CALLING_LINE_ID'])) <span>return</span><span>true</span><span>;

    </span><span>if</span> (<span>strpos</span>(<span>strtoupper</span>(<span>$_SERVER</span>['HTTP_ACCEPT']), "VND.WAP.WML") > 0<span>) {

        </span><span>//</span><span> Check whether the browser/gateway says it accepts WML.</span><span>$br</span> = "WML"<span>;

    } </span><span>else</span><span> {

        </span><span>$browser</span> = <span>isset</span>(<span>$_SERVER</span>['HTTP_USER_AGENT']) ? <span>trim</span>(<span>$_SERVER</span>['HTTP_USER_AGENT']) : ''<span>;

        </span><span>if</span> (<span>empty</span>(<span>$browser</span>)) <span>return</span><span>true</span><span>;

        </span><span>$clientkeywords</span> = <span>array</span><span>(

            </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>        );

        </span><span>if</span> (<span>preg_match</span>("/(" . <span>implode</span>('|', <span>$clientkeywords</span>) . ")/i", <span>$browser</span>) && <span>strpos</span>(<span>$browser</span>, 'ipad') === <span>false</span><span>) {

            </span><span>$br</span> = "WML"<span>;

        } </span><span>else</span><span> {

            </span><span>$br</span> = "HTML"<span>;

        }

    }

    </span><span>if</span> (<span>$br</span> == "WML"<span>) {

        </span><span>return</span><span>TRUE</span><span>;

    } </span><span>else</span><span> {

        </span><span>return</span><span>FALSE</span><span>;

    }

}

 

 

</span>?><br>然后在phpcms/templates/default模版文件夹里建立一个文件夹存放手机站的模版<br>我建立一个叫mobile的文件夹<br>然后修改

登入後複製

1

phpcms/templates/modules/content/index.php文件<br>麻烦点,分别在频道页,列表页,内容页加载模版时进行判断<br>比如:

登入後複製

1

2

3

4

<span>if</span><span> (check_wap()) {

                </span><span><strong>include</strong></span> template('mobile', <span>$template</span><span>);

            } </span><span>else</span><span> {</span><span><strong>include</strong></span> template('content', <span>$template</span><span>);

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

登入後複製

1

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

登入後複製

以上就介紹了PHPCMS搭建wap手機網站,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板