phpcms完成挪动端以及电脑端没有同模板
一、起首关上phpcms/libs/functions/global.func.php,正在文件最初面加一个isMobile()办法,用来判别能否是手机端关上
function isMobile() { // 假如有HTTP_X_WAP_PROFILE则肯定是挪动设施 if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) { return true; } // 假如via信息含有wap则肯定是挪动设施,局部效劳商会屏蔽该信息 if (isset($_SERVER['HTTP_VIA'])) { // 找没有到为flase,不然为true return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false; } // 脑残法,判别手机发送的客户端标记,兼容性有待进步。此中'MicroMessenger'是电脑微信 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'); // 从HTTP_USER_AGENT中查找手机阅读器的要害字 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { return true; } } // 协定法,由于有可能不许确,放到最初判别 if (isset ($_SERVER['HTTP_ACCEPT'])) { // 假如只支持wml而且没有支持html那肯定是挪动设施 // 假如支持wml以及html然而wml正在html以前则是挪动设施 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; }
二、而后关上phpcms/modules/content/index.php,有三个中央要改的
a)找到首页的init办法,正在最初加载模板的时分,做一个判别,假如是手机端关上就加载手机端模板,假如是电脑端关上就加载电脑端模板
大略正在31行找到:
include template('content','index',$default_style);
改为:
if(isMobile()){ include template('mobile','index',$default_style); }else{ include template('content','index',$default_style); }
b)找到内容页的show办法,一样正在最初加载模板的时分做一个判别
大略正在203行找到:
include template('content',$template);
改为:
if(isMobile()){ include template('mobile',$template); }else{ include template('content',$template); }
c)找到列表页的lists办法,一样正在最初加载模板的时分做一个判别
大略正在265行以及278行,这里有两处,找到:
include template('content',$template); 改为: if(isMobile()){ include template('mobile',$template);}else{ include template('content',$template); }
正在你以后的模板目次下新建一个mobile目次,用来寄存手机端模板
假如你以后的模板目次是phpcms/templates/default,那末你就正在phpcms/templates/default上面建一个mobile目次。
假如你以后的模板目次是phpcms/templates/moban,那末你就正在phpcms/templates/moban上面建一个mobile目次。
这样就能够完成电脑端以及手机端辨别加载没有同的模板。
PHP中文网,年夜量的收费PHPCMS教程,欢送正在线学习!
以上就是phpcms完成挪动端以及电脑端没有同模板的具体内容,更多请存眷资源魔其它相干文章!
标签: phpcms phpcms教程 phpcms技巧 php问题解决 不同模板
抱歉,评论功能暂时关闭!