dede织梦系统使手机wap模板能使用pc模板的功能

2025-10-28 06:37:23

1、首先在后台添加一个wap模板的变量,系统——系统基本参数——添加新变量

dede织梦系统使手机wap模板能使用pc模板的功能

2、打开include目录下的common.inc.php,在58行

function _RunMagicQuotes(&$svar)函数前加一个判断是否手机浏览的函数

function is_mobile_request()   {   

$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';    

$mobile_browser = '0';    

if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))     

$mobile_browser++;    

if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))    

  $mobile_browser++;    

if(isset($_SERVER['HTTP_X_WAP_PROFILE']))     

$mobile_browser++;    

if(isset($_SERVER['HTTP_PROFILE']))     

$mobile_browser++;    

$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));    

$mobile_agents = array('w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-' );    

if(in_array($mobile_ua, $mobile_agents))    

$mobile_browser++;    

if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)     

$mobile_browser++;    // Pre-final check to reset everything if the user is on Windows    

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)     

$mobile_browser=0;    // But WP7 is also Windows, with a slightly different characteristic    

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)     

$mobile_browser++;    

if($mobile_browser>0)     

return true;    

else   

return false; 

}

dede织梦系统使手机wap模板能使用pc模板的功能

3、打开include目录下的common.inc.php,找到

require_once(DEDEDATA."/config.cache.inc.php");

在下面加入代码:

if(is_mobile_request() && !isset($_GET['ispic'])){

$cfg_df_style=$cfg_wap_style;

}

如果是手机端访问,把模板目录缓存手机模板目录,如果在手机端浏览电脑版,在地址后面加上?ispic=1

dede织梦系统使手机wap模板能使用pc模板的功能

4、然后修改根目录下首页index.php代码,首页必须动态浏览,不使用生成静态页,删除首页所有代码,首页全部代码更改为:

<?php

    require_once (dirname(__FILE__) . "/include/common.inc.php");

    require_once DEDEINC."/arc.partview.class.php";

    $GLOBALS['_arclistEnv'] = 'index';

    

    $pv = new PartView();

if(is_mobile_request() && !isset($_GET['ispic'])){

$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $cfg_wap_style . '/index.htm');

}else{

$row = $dsql->GetOne("Select * From `#@__homepageset`");

    $row['templet'] = MfTemplet($row['templet']);

    $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);

}

    $row['showmod'] = isset($row['showmod'])? $row['showmod'] : 0;

        $pv->Display();

        exit();

?>

dede织梦系统使手机wap模板能使用pc模板的功能

5、然后在手机模板目录创建模板,模板名称与pc模板名称一致。首页、列表页、内容页模板都要创建。

dede织梦系统使手机wap模板能使用pc模板的功能

6、用手机打开首页显示效果

dede织梦系统使手机wap模板能使用pc模板的功能

7、有个缺点是模板中栏目和内容页的地址需要使用动态的如/plus/list.php?tid=栏目id,内容页可以修改代码自动生成html页,前面文章有过介绍

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢