大家對本博客帖子《DedeCMS多條件篩選以篩選詞爲標題》即最新版DedeCMS V5.7自定義篩選功能基本都能掌握了,接下來分享本人研究整理的一個後臺管理移動端、PC用JS代碼匹配跳轉,如果還想做成僞靜態,文章有點長就慢慢看咯。
一個後臺管理生成移動端和PC端的靜態頁面
如果用一個後臺管理PC和移動端,不用dede默認的移動端模板,
動態列表判斷當前設備自動跳轉
篩選列表爲動態列表,未作僞靜態前,一般路徑爲:域名/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找到
1 |
include(DEDEINC. "/arc.sglistview.class.php" ); |
2 |
$lv = new SgListView($tid,$cArr); |
4 |
include(DEDEINC. "/arc.listview.class.php" ); |
|
修改爲
1 |
include(DEDEINC. "/wap_arc.sglistview.class.php" ); |
2 |
$lv = new SgListView($tid,$cArr); |
4 |
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目錄下的模板路徑,根據實際情況填寫
02 |
$tempfile = $GLOBALS[ 'cfg_basedir' ].$GLOBALS[ 'cfg_templets_dir' ]. "/" .$this->TypeLink->TypeInfos[ 'templist' ]; |
03 |
$tempfile = str_replace( "{tid}" ,$this->TypeID,$tempfile); |
04 |
$tempfile = str_replace( "{cid}" ,$this->ChannelUnit->ChannelInfos[ 'nid' ],$tempfile); |
06 |
$tempfile = str_replace( "/pc/" , "/wap/" ,$tempfile) |
07 |
if (!file_exists($tempfile)) |
09 |
$tempfile = str_replace( "/wap/" , "/pc/" ,$tempfile); |
|
5.用《DedeCMS一個後臺管理PC和移動端純靜態非官方版》的方法需要PC和移動端模板下的各個頻道所使用的模板名稱完全一樣。
6.跳轉代碼很多種,文章《DedeCMS電腦端列表和內容跳轉到對應移動端》是靜態列表,下面是動態列表的方法。
在系統-系統基本參數-添加新變量:變量名爲stylewap,變量值爲wap,參數說明爲移動端模板,把以下代碼放到相應的列表模板即可:
1 |
<meta http-equiv= "mobile-agent" content= "format=xhtml;url={dede:global.stylewap/}/plus/wap_list.php?tid={dede:field.id/}" > |
2 |
<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篩選列表僞靜態規則詳細可參考文章《DedeCMS織夢程序實現全站php僞靜態》;建立.htaccess文件創建方法參考《調試.htaccess網站出現500錯誤》,常見的僞靜態規則寫法。
2 |
RewriteRule ^list-([0-9]+).html$ /plus/list.php?tid=$1 |
3 |
RewriteRule ^list-([0-9]+)-([0-9]+)-([0-9]+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 |
4 |
RewriteRule ^view-([0-9]+)-1.html$ /plus/view.php?arcID=$1 |
5 |
RewriteRule ^view-([0-9]+)-([0-9]+).html$ /plus/view.php?aid=$1&pageno=$2 |
6 |
RewriteRule ^index.html$ index.php |
|
由於原來DedeCMS多條件篩選編寫者並沒有給出對應的僞靜態規則,如果按照上訴的僞靜態規則
1 |
/plus/list.php?tid=1 url重寫爲 |
|
則該列表頁下的篩選url如下,這明顯是不正確的
1 |
/list-1.html&zxfg=%a%b%c |
|
筆者嘗試用str_replace函數調整爲
1 |
/list-1&zxfg=%a%b%c.html |
|
能正常篩選,但有輕微bug,不影響使用。
現在筆者給出dede篩選列表專有.htaccess僞靜態規則
2 |
RewriteRule ^list-(.*)$ /plus/list.php?tid=$1 |
|
url重寫就不含有“.html”,最終樣式
1 |
/plus/list.php?tid=1重寫爲 |
|
打開/include/helpers/channelunit.help.php,找到
2 |
$reurl = $GLOBALS[ 'cfg_phpurl' ]. "/list.php?tid=" .$typeid; |
|
修改爲
2 |
$reurl = "/list-" .$typeid; |
|
其他兩個文件修改參考文章《DedeCMS多條件篩選以篩選詞爲標題》,篩選url僞靜態/include/extend.func.php文件需要調整,找到
1 |
$filterarr = wwwcms_filter(stripos($_SERVER[ 'REQUEST_URI' ], "list.php?tid=" ) ? str_replace($nofilter, '' , $_SERVER[ 'REQUEST_URI' ]) : $GLOBALS[ 'cfg_cmsurl' ]. "/plus/list.php?tid=" .$tid); |
|
修改爲
1 |
$filterarr = wwwcms_filter(stripos($_SERVER[ 'REQUEST_URI' ], "list-" ) ? str_replace($nofilter, '' , $_SERVER[ 'REQUEST_URI' ]) : $GLOBALS[ 'cfg_cmsurl' ]. "/list-" .$tid); |
|