注意:我的手机模块本身就是二开过的,所以一下修改请你考虑自己的实际情况 一、后台模板修改部分 (1)打开phpcms\modules\wap\templates\m_edit.tpl.php在45行后边加入代码(m_add.tpl.php的45行处也加上):
<th width="100">开启伪静态:</th><td class="y-bg"><input type="radio" name="setting[nohtml]" value="0" id="nohtml" <?php if (!$nohtml) echo 'checked';?>>关闭 <input type="radio" name="setting[nohtml]" value="1" id="nohtml" <?php if ($nohtml) echo 'checked';?> >开启</td>
</tr>
<tr id="weijingtai" style="width:100%;">
<th width="100px" style="width:100px;">伪静态规则:</th>
<td class="y-bg"><input type="text" class="input-text" name="setting[nohtml_list]" id="nohtml_list" size="50" value="<?php echo $nohtml_list?>"/><br/><br/>
<input type="text" class="input-text" name="setting[nohtml_show]" id="nohtml_show" size="50" value="<?php echo $nohtml_show?>"/><br/>
<br/>
<font style="font-size:10px; color:#666666">list默认:list-{$typeid}|list-{$typeid}-{$page}<br/>
show默认: show-{$catid}-{$typeid}-{$id}-1</font><br/>
</td>
</tr>
效果: 二、源码部分修改 (1)打开phpcms\modules\wap\index.php修改如下:
define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid);改成:
$setting = json_decode($this->wap['setting'], true); if($setting['nohtml']){ define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'] : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); }else{ define('WAP_SITEURL', $this->wap['domain'] ? $this->wap['domain'].'index.php?' : APP_PATH.'index.php?m=wap&siteid='.$this->siteid); }把:
//构造wap url规则 define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');替换成:
//构造wap url规则 /*判断伪静态*/ $setting = json_decode($this->wap_site[$siteid]['setting'], true); if($setting['nohtml']){ $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}|list-{$typeid}-{$page}'; if($setting['nohtml_list']){ // $nohtml_list = str_replace("|","~",$setting['nohtml_list']); //$nohtml_list = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$nohtml_list); define('URLRULE', $nohtml_list.'.html'); }else{ define('URLRULE', 'list-{$typeid}-{$page}.html'); } }else{ define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}'); }(2)修改phpcms\modules\wap\functions\global.func.php文件 把list_url方法里边的
return WAP_SITEURL."&a=lists&typeid=$typeid";改成:
/*判断开启伪静态*/ $dbs = pc_base::load_model('wap_model'); $infos = $dbs->select(); foreach($infos as $k => $info){ if($info['siteid'] == $siteid ){ $setting = json_decode($infos[$k]['setting'], true); } } if(!array_key_exists('nohtml', $setting)){ $nohtml = 0; }else{ $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0; } if($nohtml){ $page = 1; $setting['nohtml_list'] = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']): 'list-{$typeid}-{$page}'; $nohtml_url = str_replace(array('{$typeid}','{$catid}','{$page}'),array($typeid,$catid,$page),$setting['nohtml_list']); return "/".$nohtml_url.'.html';//可以自定义伪静态 }else{ return WAP_SITEURL."&a=lists&typeid=$typeid"; }show_url方法中做同样修改
return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";替换成:
/*判断开启伪静态*/ $siteid = $GLOBALS['siteid']; $dbs = pc_base::load_model('wap_model'); $infos = $dbs->select(); foreach($infos as $k => $info){ if($info['siteid'] == $siteid ){ $setting = json_decode($infos[$k]['setting'], true); } } if(!array_key_exists('nohtml', $setting)){ $nohtml = 0; }else{ $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0; } if($nohtml){ $html_show = trim($setting['nohtml_show']) ? trim($setting['nohtml_show']) :'show-{$catid}-{$typeid}-{$id}-1'; $html_show = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_show); return "/".$html_show.'.html'; }else{ return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id"; }并且并强烈建议新增一个调用某个栏目url的函数
/* * 新增 获取当前页面的栏目的url * typeid 栏目id */ function caturl($typeid) { if(!empty($typeid)){ /*判断开启伪静态*/ if (empty($siteid)) $siteid = $GLOBALS['siteid']; $dbs = pc_base::load_model('wap_model'); $infos = $dbs->select(); foreach($infos as $k => $info){ if($info['siteid'] == $siteid ){ $setting = json_decode($infos[$k]['setting'], true); } } if(!array_key_exists('nohtml', $setting)){ $nohtml = 0; }else{ $nohtml = trim($setting['nohtml']) ? trim($setting['nohtml']) : 0; } if($nohtml){ $page = 1; $html_list = trim($setting['nohtml_list']) ? trim($setting['nohtml_list']) :'list-{$typeid}-{$page}'; $html_list = str_replace(array('{$typeid}','{$catid}','{$page}','{$id}'),array($typeid,$catid,$page,$id),$html_list); return "/".$html_list.'.html'; }else{ return WAP_SITEURL."&a=lists&typeid=$typeid"; } }else{ return WAP_SITEURL; } }这样我们就可以直接调用{caturl(7)}的栏目链接,而无需关心伪静态开启还是关闭。
另外由于默认的伪静态路径和pc站的伪静态路径,所以设置伪静态规则的时候一定要先判断一下 我用的是nginx,伪静态写法为:
location / { if ($host = 'm.tengcee.com' ) { rewrite ^(.*)/list-([0-9]+)-([0-9]+)\.html$ $1/index.php?&a=lists&typeid=$2&page=$3; rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?&a=show&catid=$2&typeid=$3&id=$4; } rewrite ^(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4; rewrite ^(.*)show-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4; rewrite ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/index.php?m=content&c=index&a=lists&catid=$2&page=$3; }appach写法:还未测试暂时不公布 以上就是全部教程,有想测试的可以去测试,有什么问题请及时反馈给我,谢谢!
dede小程序插件【官方】 dede小程序插 phpcms v9小程序插件、dedecms小程序插件,织梦小程序插件官方,cms小程序插件api接口使用、小程序插件开发,郑州腾石网络科技有限公司,咨询QQ:2863868475【官方账号】