ecshop PC版本智能跳转到对应手机版页面
更新时间:2018-04-13 点击量:1303
Tag关键词: 手机 ecshop模板 ecshop4.0模板 二次开发 ecshop3.6模板 ecshop小程序
以下适用于PC跳转到ectouch手机版的写法。其他手机端的方法类似。
修改文件 includes/lib_main.php 增加以下
/** * ecshop 实现其他页面(商品详情页、商品分类页、团购页、优惠活动页、积分商城) * 判断如果是智能手机访问的话 跳转到Ectouch1.0手机版对应页面 方法 * * @access public */ function pc_to_mobile() { //判断是否是手机访问 $is_mobile = false; $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap')) { $is_mobile = true; } /* 判断是否重写,取得文件名 */ $cur_url = basename(PHP_SELF); if (intval($GLOBALS['_CFG']['rewrite'])){ $filename = strpos($cur_url,'-') ? substr($cur_url, 0, strpos($cur_url,'-')) : substr($cur_url, 0, -4); }else{ $filename = substr($cur_url, 0, -4); } if($is_mobile){ /* * 如果你绑定了手机版域名 http://www.uuecs.com/mobile 为 http://m.abc.com * 那么 $mobile_url = http://m.uuecs.com */ $mobile_url = $GLOBALS['ecs']->url().'mobile'; /* 根据文件名分别处理中间的部分 */ if ($filename != 'index') { /* 处理有分类的 */ if (in_array($filename, array('category', 'goods', 'brand'))) { /* 商品分类或商品 */ if ('category' == $filename || 'goods' == $filename || 'brand' == $filename) { $Loaction = $mobile_url .'/?c='.$filename.'&a=index&'.$_SERVER["QUERY_STRING"]; } } /* 处理无分类的 */ else { /* 团购 */ if ('group_buy' == $filename) { if(!empty($_GET['id'])){ $Loaction = $mobile_url .'/?c=groupbuy&a=info&id='.$_GET['id']; }else{ $Loaction = $mobile_url .'/?c=groupbuy'; } } /* 拍卖 */ elseif ('auction' == $filename) { if(!empty($_GET['id'])){ $Loaction = $mobile_url .'/?c=auction&a=info&id='.$_GET['id']; }else{ $Loaction = $mobile_url .'/?c=auction'; } } /* 夺宝 */ elseif ('snatch' == $filename) { if(!empty($_GET['id'])){ $Loaction = $mobile_url .'/?c=snatch&a=info&id='.$_GET['id']; }else{ $Loaction = $mobile_url .'/?c=snatch'; } } /* 批发 */ elseif ('wholesale' == $filename) { if(!empty($_GET['id'])){ $Loaction = $mobile_url .'/?c=wholesale&a=info&id='.$_GET['id']; }else{ $Loaction = $mobile_url .'/?c=wholesale'; } } /* 积分兑换 */ elseif ('exchange' == $filename) { if(!empty($_GET['id'])){ $Loaction = $mobile_url .'/?c=exchange&a=exchange_goods&gid='.$_GET['id']; }else{ $Loaction = $mobile_url .'/?c=exchange'; } } /* 优惠活动 */ elseif ('activity' == $filename) { $Loaction = $mobile_url .'/?c=activity'; } } /* ecshop跳转到手机对应页面 */ if (!empty($Loaction)){ ecs_header("Location: $Loaction"); exit; } } } }
随后在 includes/init.php 增加到最底部 ?>前即可。
pc_to_mobile();
如果文章对您有帮助,就打赏一个吧