之前写过这篇文章《织梦DEDECMS5.7实现联动筛选(支持多条件多级选项)》下面二次开发织梦联动筛选是之前升级版,修复手机端无法加载_m.htm列表模板BUG:
首先需要说明的是这个功能需要在模板里面用到php标签,所以需要在后台模板引擎禁用标签里面解除这个标签的禁用,具体方法:
登录后台 >> 系统 >> 系统基本参数 >> 其它选项 >> 模板引擎禁用标签:php
将这个php删除后保存就可以了!
联动筛选功能分为两种,单选和多选,好了,下面开始正题。
一、联动功能 单选
首先需要修改2个PHP文件,用编辑器打开include目录下的 arc.listview.class.php 和 extend.func.php
1、修改arc.listview.class.php,这个文件改动的地方较多,建议大家直接下载附件压缩包里面的文件,直接替换。
注意:如果你曾经对arc.listview.class.php这个文件进行过改动的话,请先备份原文件,再对比“参照表”逐一手动替换!
2、修改extend.func.php文件,这个文件改动很简单,直接在最后面添加如下代码:
特别注意:以下代码中有4处“【分隔符】”字样,请自行删除。
// 字符过滤函数
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;
}
// 织梦58
// 载入自定义表单(用于发布)
// @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 `#【分隔符】@__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 `#【分隔符】@__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 .= '<div class="scv-shaixuan"><b>'.$ctag->GetAtt('itemname').':</b>';
switch ($type) {
case 1:
$lola = $ctag->GetName();
$dederow = $dsql->GetOne("SELECT count($lola) FROM #【分隔符】@__addonarticle WHERE $lola");
$dederowz = $dederow["count($lola)"];
$dede_addonfields .= (preg_match("/&".$ctag->GetName()."=http://www.dede58.com/is",$filterarr,$regm) ? '<a title="全部" href="'.str_replace("&".$ctag->GetName()."=".$fields_value,"",$filterarr).'">全部('.$dederowz.')</a>' : '<span>全部('.$dederowz.')</span>').' ';
$addonfields_items = explode(",",$ctag->GetAtt('default'));
for ($i=0; $i<count($addonfields_items); $i++)
{
$lola = $ctag->GetName();
$lolb = $addonfields_items[$i];
$dederow = $dsql->GetOne("SELECT count(*) FROM #【分隔符】@__addonarticle WHERE $lola='$lolb'");
$dederows = $dederow["count(*)"];
$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].'(<span>'.$dederows.'</span>)</a>' : '<span>'.$addonfields_items[$i].'('.$dederows.')</span>')." ";
}
$dede_addonfields .= '</div>';
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文件修改的部分就完成了!接下来就需要给指定的模型添加字段了,添加步骤:登录后台 >> 核心 >> 内容模型管理 >> (选择频道名称) >> 字段管理 >> 添加新字段
这里需要注意的就是字段类型的选择,字段类型需要选择“使用option下拉框”或者“使用radio选项卡”,如下图所示: