大家對本博客帖子《DedeCMS多條件篩選以篩選詞為標題》即最新版DedeCMS V5.7自定義篩選功能基本都能掌握了,接下來分享本人研究整理的一個后臺管理移動端、PC用JS代碼匹配跳轉,如果還想做成偽靜態,文章有點長就慢慢看咯。
如果用一個后臺管理PC和移動端,不用dede默認的移動端模板,參考文章《DedeCMS一個后臺管理PC和移動端純靜態非官方版》。
篩選列表為動態列表,未作偽靜態前,一般路徑為:域名/plus/list.php?tid=1。移動端的靜態頁面實際上是依靠更新時切換模板實現的,但對篩選的動態列表卻不能實現移動端和PC端模板的自動選擇。經筆者測試有效方法如下:
1.復制/plus目錄下的list.php更名為wap_list.php;
2.復制/include目錄下arc.sglistview.class.php和arc.listview.class.php并分別更名為wap_arc.sglistview.class.php和wap_arc.listview.class.php;
3.打開wap_list.php找到
include(DEDEINC."/arc.sglistview.class.php"); $lv = new SgListView($tid,$cArr);} else { include(DEDEINC."/arc.listview.class.php"); |
修改為
include(DEDEINC."/wap_arc.sglistview.class.php"); $lv = new SgListView($tid,$cArr);} else { include(DEDEINC."/wap_arc.listview.class.php"); |
4.打開/include/wap_arc.sglistview.class.php,v5.7版本在2015年6月更新后增加了移動端的自適應,如果是老版本的找到相應的位置修改就好,大概在227行,/include/wap_arc.listview.class.php,大概在266行,橙色部分為增加內容:"/pc/"和"/wap/"為/templates目錄下的模板路徑,根據實際情況填寫
//初始化列表模板,并統計頁面總數$tempfile = $GLOBALS['cfg_basedir'].$GLOBALS['cfg_templets_dir']."/".$this->TypeLink->TypeInfos['templist'];$tempfile = str_replace("{tid}",$this->TypeID,$tempfile);$tempfile = str_replace("{cid}",$this->ChannelUnit->ChannelInfos['nid'],$tempfile);//增加wap$tempfile = str_replace("/pc/","/wap/",$tempfile)if(!file_exists($tempfile)){$tempfile = str_replace("/wap/","/pc/",$tempfile);}//增加wap |
5.用《DedeCMS一個后臺管理PC和移動端純靜態非官方版》的方法需要PC和移動端模板下的各個頻道所使用的模板名稱完全一樣。
6.跳轉代碼很多種,文章《DedeCMS電腦端列表和內容跳轉到對應移動端》是靜態列表,下面是動態列表的方法。
在系統-系統基本參數-添加新變量:變量名為stylewap,變量值為wap,參數說明為移動端模板,把以下代碼放到相應的列表模板即可:
<meta http-equiv="mobile-agent" content="format=xhtml;url={dede:global.stylewap/}/plus/wap_list.php?tid={dede:field.id/}"><script type="text/javascript">if(window.location.toString().indexOf('pref=padindex') != -1){}else{if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){if(window.location.href.indexOf("?mobile")<0){try{if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){window.location.href="{dede:global.stylewap/}/plus/wap_list.php?tid={dede:field.id/}";}else if(/iPad/i.test(navigator.userAgent)){}else{}}catch(e){}}}}</script> |
DedeCMS篩選偽靜態規則請看下一頁。
DedeCMS篩選列表偽靜態規則詳細可參考文章《DedeCMS織夢程序實現全站php偽靜態》;建立.htaccess文件創建方法參考《調試.htaccess網站出現500錯誤》,常見的偽靜態規則寫法。
RewriteEngine onRewriteRule ^list-([0-9]+).html$ /plus/list.php?tid=$1RewriteRule ^list-([0-9]+)-([0-9]+)-([0-9]+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3RewriteRule ^view-([0-9]+)-1.html$ /plus/view.php?arcID=$1RewriteRule ^view-([0-9]+)-([0-9]+).html$ /plus/view.php?aid=$1&pageno=$2RewriteRule ^index.html$ index.php |
由于原來DedeCMS多條件篩選編寫者并沒有給出對應的偽靜態規則,如果按照上訴的偽靜態規則
/plus/list.php?tid=1 url重寫為/list-1.html |
則該列表頁下的篩選url如下,這明顯是不正確的
/list-1.html&zxfg=%a%b%c |
筆者嘗試用str_replace函數調整為
/list-1&zxfg=%a%b%c.html |
能正常篩選,但有輕微bug,不影響使用。
現在筆者給出dede篩選列表專有.htaccess偽靜態規則
RewriteEngine onRewriteRule ^list-(.*)$ /plus/list.php?tid=$1 |
url重寫就不含有“.html”,最終樣式
/plus/list.php?tid=1重寫為/list-1 |
打開/include/helpers/channelunit.help.php,找到
//動態$reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid; |
修改為
//動態$reurl = "/list-".$typeid; |
其他兩個文件修改參考文章《DedeCMS多條件篩選以篩選詞為標題》,篩選url偽靜態/include/extend.func.php文件需要調整,找到
$filterarr = wwwcms_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid); |
修改為
$filterarr = wwwcms_filter(stripos($_SERVER['REQUEST_URI'], "list-") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/list-".$tid); |
新聞熱點
疑難解答