Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of realizing different templates between Mobile end and computer side by phpcms

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is the method of implementing different templates between mobile and computer by phpcms? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

Phpcms implements different templates for mobile and computer

1. Open phpcms/libs/functions/global.func.php first, and add an isMobile () method at the end of the file to determine whether it is opened by the mobile phone.

Function isMobile () {/ / if there is a HTTP_X_WAP_PROFILE, it must be the mobile device if (isset ($_ SERVER ['HTTP_X_WAP_PROFILE'])) {return true } / / if the via message contains wap, it must be a mobile device, and some services will block the information if (isset ($_ SERVER ['HTTP_VIA'])) {/ / cannot be found as flase, otherwise it is true return stristr ($_ SERVER [' HTTP_VIA'], "wap")? True: false;} / / mental disability method to judge the client logo sent by mobile phone, the compatibility needs to be improved. Where 'MicroMessenger' is the computer Wechat if (isset ($_ SERVER [' HTTP_USER_AGENT'])) {$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','openwave','nexusone','cldc','midp','wap','mobile','MicroMessenger') / / find the keyword if (preg_match ("/ (")) of the mobile browser from HTTP_USER_AGENT. Implode ('|', $clientkeywords). ") / I", strtolower ($_ SERVER ['HTTP_USER_AGENT']) {return true }} / / Agreement Law, because it may be inaccurate At last, if (isset ($_ SERVER ['HTTP_ACCEPT'])) {/ / if only wml is supported and html is not supported, it must be a mobile device / / if wml and html are supported, but before html, wml is a mobile device if ((strpos ($_ SERVER [' HTTP_ACCEPT'], 'vnd.wap.wml')! = false) & & (strpos ($_ SERVER [' HTTP_ACCEPT']) 'text/html') = = false | (strpos ($_ SERVER [' HTTP_ACCEPT'], 'vnd.wap.wml') < strpos ($_ SERVER [' HTTP_ACCEPT'], 'text/html') {return true }} return false;}

2. Then open phpcms/modules/content/index.php. There are three things to change.

A) find the init method on the front page, and when you finally load the template, make a judgment: load the mobile template if it is opened on the mobile side, and load the template on the computer side if it is opened on the computer side.

You can find it on line 31:

Include template ('content','index',$default_style)

Change it to:

If (isMobile ()) {include template ('mobile','index',$default_style);} else {include template (' content','index',$default_style);}

B) find the show method of the content page, and also make a judgment when the template is finally loaded

Find it at line 203 or so:

Include template ('content',$template)

Change it to:

If (isMobile ()) {include template ('mobile',$template);} else {include template (' content',$template);}

C) find the lists method of the list page, and also make a judgment when the template is finally loaded

About on lines 265 and 278, here are two places to find:

Include template ('content',$template); change it to: if (isMobile ()) {include template (' mobile',$template);} else {include template ('content',$template);}

Create a new mobile directory under your current template directory to store the mobile template.

If your current template directory is phpcms/templates/default, then you can create a mobile directory under phpcms/templates/default.

If your current template directory is phpcms/templates/moban, then you can create a mobile directory under phpcms/templates/moban.

In this way, it is possible to load different templates on the computer side and the mobile end.

Thank you for reading! After reading the above, do you have a general idea of how phpcms implements different templates for mobile and computer? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report