很多織夢(mèng)建站的站長(zhǎng)在做產(chǎn)品列表頁(yè)的時(shí)候,產(chǎn)品分類多而且都是關(guān)聯(lián)的,用戶不能快速的找到自己需要的東西,很多情況下都需要用到篩選功能,織夢(mèng)后臺(tái)列表頁(yè)默認(rèn)是沒(méi)有聯(lián)動(dòng)篩選功能,實(shí)現(xiàn)這個(gè)聯(lián)動(dòng)篩選功能需要對(duì)織夢(mèng)進(jìn)行二次開發(fā),接下來(lái)教大家如何實(shí)現(xiàn)這個(gè)聯(lián)動(dòng)篩選功能,如下圖所示:
注:因?yàn)榭棄?mèng)默認(rèn)是禁止使用php標(biāo)簽,所以需要在后臺(tái)模板引擎禁用標(biāo)簽里面解除這個(gè)標(biāo)簽的禁用,具體方法: 后臺(tái)——系統(tǒng)——系統(tǒng)基本參數(shù)——其它選項(xiàng)——模板引擎禁用標(biāo)簽:php 將這個(gè)PHP去掉后保存就可以了!
第一步:修改include目錄下arc.listview.class.php,修改地方很多,下載地址為:
第二步:打開include目錄下extend.func.php文件在底部加入以下代碼:
//dedecms聯(lián)動(dòng)篩選功能 By function wwwcms_filter($str,$stype="inject") { if ($stype=="inject") { $str = str_replace( array( "select", "insert", "update", "delete", "alter", "cas", "union", "into", "load_file", "outfile", "create", "join", "where", "like", "drop", "modify", "rename", "'", "/*", "*", "../", "./"), array("","","","","","","","","","","","","","","","","","","","","",""), $str); } else if ($stype=="xss") { $farr = array("/\s+/" , "/<(\/?)(script|META|STYLE|HTML|HEAD|BODY|STYLE |i?frame|b|strong|style|html|img|P|o:p|iframe|u |em|strike|BR|div|a|TABLE|TBODY|object|tr|td |st1:chsdate|FONT|span|MARQUEE|body|title |\r\n|link |meta|\?|\%)([^>]*?)>/isU", "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU", ); $tarr = array(" ", "", "\\1\\2", ); $str = preg_replace($farr, $tarr, $str); $str = str_replace( array( "<", ">", "'", "\"", ";", "/*", "*", "../", "./"), array("<",">","","","","","","",""), $str); } return $str; } /** * 載入自定義表單(用于發(fā)布) * * @access public * @param string $fieldset 字段列表 * @param string $loadtype 載入類型 * @return string */ function AddFilter($channelid, $type=1, $fieldsnamef, $defaulttid, $loadtype='autofield') { global $tid,$dsql,$id; $tid = $defaulttid ? $defaulttid : $tid; if ($id!="") { $tidsq = $dsql->GetOne(" Select typeid From `dede_archives` where id='$id' "); $tid = $tidsq["typeid"]; } $nofilter = (isset($_REQUEST['TotalResult']) ? "&TotalResult=".$_REQUEST['TotalResult'] : '').(isset($_REQUEST['PageNo']) ? "&PageNo=".$_REQUEST['PageNo'] : ''); $filterarr = wwwcms_filter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/plus/list.php?tid=".$tid); $cInfos = $dsql->GetOne(" Select * From `dede_channeltype` where id='$channelid' "); $fieldset=$cInfos['fieldset']; $dtp = new DedeTagParse(); $dtp->SetNameSpace('field','<','>'); $dtp->LoadSource($fieldset); $dede_addonfields = ''; if(is_array($dtp->CTags)) { foreach($dtp->CTags as $tid=>$ctag) { $fieldsname = $fieldsnamef ? explode(",", $fieldsnamef) : explode(",", $ctag->GetName()); if(($loadtype!='autofield' || ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1)) && in_array($ctag->GetName(), $fieldsname) ) { $href1 = explode($ctag->GetName().'=', $filterarr); $href2 = explode('&', $href1[1]); $fields_value = $href2[0]; $dede_addonfields .= '<dl><dt>'.$ctag->GetAtt('itemname').':</dt><dd>'; switch ($type) { case 1: $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? '<a title="全部" href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</a>' : '<dd><a class="on">全部</a>').' '; $addonfields_items = explode(",",$ctag->GetAtt('default')); for ($i=0; $i<count($addonfields_items); $i++) { $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]);//echo $href; $dede_addonfields .= ($fields_value!=urlencode($addonfields_items[$i]) ? '<a title="'.$addonfields_items[$i].'" href="'.$href.'">'.$addonfields_items[$i].'</a>' : '<a class="on">'.$addonfields_items[$i].'</a>')." "; } $dede_addonfields .= '</dl>'; break; case 2: $dede_addonfields .= '<select name="filter"'.$ctag->GetName().' onchange="window.location=this.options[this.selectedIndex].value"> '.'<option value="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部</option>'; $addonfields_items = explode(",",$ctag->GetAtt('default')); for ($i=0; $i<count($addonfields_items); $i++) { $href = stripos($filterarr,$ctag->GetName().'=') ? str_replace("=".$fields_value,"=".urlencode($addonfields_items[$i]),$filterarr) : $filterarr.'&'.$ctag->GetName().'='.urlencode($addonfields_items[$i]); $dede_addonfields .= '<option value="'.$href.'"'.($fields_value==urlencode($addonfields_items[$i]) ? ' selected="selected"' : '').'>'.$addonfields_items[$i].'</option> '; } $dede_addonfields .= '</select><br/> '; break; } } } } echo $dede_addonfields; } |
第三步:到這里PHP文件修改的部分就完成了!接下來(lái)就需要給指定的模型添加字段了,這里需要注意的就是 字段類型的選擇,字段類型需要選擇單選按鈕或者使用select下拉框,如下圖所示:
第四部: 前臺(tái)調(diào)用標(biāo)簽 {dede:php}AddFilter(3,1,'fenleia,fenleib,fenleic');{/dede:php}
注:標(biāo)簽說(shuō)明: AddFilter函數(shù)里面的第一個(gè)數(shù)字3是內(nèi)容模型的id號(hào),各個(gè)內(nèi)容模型的id請(qǐng)到后臺(tái)內(nèi)容模型管理里面查看; 第二個(gè)數(shù)字1是表示篩選的樣式,1是使用超鏈接進(jìn)行選擇,2是使用select下拉框選擇,具體可以自己設(shè)置了查看效果; 第三個(gè)部分'fenleia,fenleib,fenleic'是要添加篩選功能的字段名,這里有3個(gè)字段,注意需要用半角逗號(hào)隔開。
注:列表頁(yè)要用{dede:list pagesize='15' titlelen='60' addfields='mobanyouhuijia' channelid='2'}這樣的標(biāo)簽,選擇要有效
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)dedecms 5.7實(shí)現(xiàn)聯(lián)動(dòng)篩選(支持多條件多級(jí)選項(xiàng))