1. 后台添加自己要筛选的字段
内容模型管理-编辑模型-字段管理-添加字段
2. 调整系统设置,允许运行php标签
系统 - 系统设置 - 系统基本参数 - 其他选项 - 禁用模板标签 ,把“php”删除后保存。
3. 添加属性调用函数
找到文件:inluce/extend.func.php,添加代码:
function _extendFilter($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;}/** * 载入自定义表单(用于发布) * * @access public * @param string $fieldset 字段列表 * @param string $loadtype 载入类型 * @param string $column 文件路径(手机端首页调用时传入值为:m) * @return string */ function AddFilter($channelid, $type=1, $fieldsnamef, $defaulttid, $loadtype='autofield', $column='plus'){ 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 = _extendFilter(stripos($_SERVER['REQUEST_URI'], "list.php?tid=") ? str_replace($nofilter, '', $_SERVER['REQUEST_URI']) : $GLOBALS['cfg_cmsurl']."/".$column."/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 $tida=>$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 .= ''; $dede_addonfields .= ' '.$ctag->GetAtt('itemname').':'; switch ($type) { case 1: $dede_addonfields .= (preg_match("/&".$ctag->GetName()."=/is",$filterarr,$regm) ? ' GetName()."=".$fields_value,"",$filterarr).'">全部' : ' 全部'); $addonfields_items = explode(",",$ctag->GetAtt('default')); for ($i=0; $i'; break; case 2: $dede_addonfields .= ' '; break; } } } } echo $dede_addonfields;}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]) ? ' '.$addonfields_items[$i].'' : ' '.$addonfields_items[$i].''); } $dede_addonfields .= '
4. 修改文档列表核心文件:include/arc.listview.php
文件改动较大,可以下载后比对自己的文件修改,自己文件之前未改动的可直接覆盖
5.调用示例,以栏目id15为列
PC端当前栏目调用:{dede:php} AddFilter(2,1,'',15); {/dede:php}
PC端其他页面调用 {dede:php} AddFilter(2,1,'',15); {/dede:php}
手机端当前栏目调用:{dede:php} AddFilter(2,1,'',15); {/dede:php}
手机端其他页面调用: {dede:php} AddFilter(2,1,'',15,'autofield','m'); {/dede:php}