一、第一种方法
电脑端和手机端模板分别在不同目录,比如电脑端模板在pc目录下,手机端模板在mobile目录下
1.找到/system/helpers/extend.helper.php,在文件末尾添加下面这段代码
/**
* 判断是否为移动设备访问
* @return bool
*/
if(!function_exists(function_name)){
function isMobile(){
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
if (isset ($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], 'wap')) {
return true;
}
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');
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml')))) {
return true;
}
}
return false;
}
}
* 判断是否为移动设备访问
* @return bool
*/
if(!function_exists(function_name)){
function isMobile(){
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
if (isset ($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], 'wap')) {
return true;
}
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');
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml')))) {
return true;
}
}
return false;
}
}
2.找到/system/helpers/channelunit.helper.php中的MfTemplet函数,大概在384行,在这个函数中加入下面这段代码
// 判断是否是手机端,如果是手机端就把模板目录换成mobile
if(isMobile()){
$GLOBALS['cfg_df_style'] = 'mobile';
}
if(isMobile()){
$GLOBALS['cfg_df_style'] = 'mobile';
}
3.找到/system/archive/searchview.class.php,大概在116行,在这行上面加上下面这段代码
// 判断是否是手机端,如果是手机端就把模板目录换成mobile
if(isMobile()){
$GLOBALS['cfg_df_style'] = 'mobile';
}
if(isMobile()){
$GLOBALS['cfg_df_style'] = 'mobile';
}
4.然后在/theme/目录下创建一个mobile的目录,在这个目录下放手机端的模板,这样就可以实现电脑端和手机端使用不同的模板,两套模板在不同的目录下。
如下图所示
二、第二种方法
电脑端和手机端模板在同一个目录下,比如电脑端首页模板是index.htm,手机端模板是index_m.htm
1.找到/system/helpers/extend.helper.php,在文件末尾添加下面这段代码
/**
* 判断是否为移动设备访问
* @return bool
*/
if(!function_exists(function_name)){
function isMobile(){
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
if (isset ($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], 'wap')) {
return true;
}
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');
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml')))) {
return true;
}
}
return false;
}
}
* 判断是否为移动设备访问
* @return bool
*/
if(!function_exists(function_name)){
function isMobile(){
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
if (isset ($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], 'wap')) {
return true;
}
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');
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
if (isset($_SERVER['HTTP_ACCEPT'])) {
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'textml') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'textml')))) {
return true;
}
}
return false;
}
}
2.找到/system/helpers/channelunit.helper.php中的MfTemplet函数,大概在384行,在这个函数中加入下面这段代码
//判断是否是手机端,如果是手机端就换成_m.htm
if(isMobile() && strpos($tmpdir,'_m') === false){
$tmpdir =str_replace('.htm','_m.htm',$tmpdir);
}
if(isMobile() && strpos($tmpdir,'_m') === false){
$tmpdir =str_replace('.htm','_m.htm',$tmpdir);
}
3.找到/system/archive/searchview.class.php,大概在116行找到下面这行代码
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search.htm";
在这行代码下面加上这段代码:
if(isMobile()){
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search_m.htm";
}
$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$GLOBALS['cfg_df_style']."/search_m.htm";
}
4.找到/apps/tags.php,大概在22行找到下面这段代码
if ($tag == '') $dlist = new TagList($tag, 'tag.htm');
else $dlist = new TagList($tag, 'taglist.htm');
else $dlist = new TagList($tag, 'taglist.htm');
把这段代码换成下面这段代码
if(isMobile()){
if ($tag == '') $dlist = new TagList($tag, 'tag_m.htm');
else $dlist = new TagList($tag, 'taglist_m.htm');
}else{
if ($tag == '') $dlist = new TagList($tag, 'tag.htm');
else $dlist = new TagList($tag, 'taglist.htm');
}
if ($tag == '') $dlist = new TagList($tag, 'tag_m.htm');
else $dlist = new TagList($tag, 'taglist_m.htm');
}else{
if ($tag == '') $dlist = new TagList($tag, 'tag.htm');
else $dlist = new TagList($tag, 'taglist.htm');
}