首页 > 教程 >

织梦列表页点击按价格按评分按更新按点击排序进行筛选方法

2023-02-24教程围观

简介假如网站中,有一个价格字段trueprice,我希望根据价格从小到大,或从大到小进行点击筛选,或按热门,最新商品进行排序,效果图如下(此图片来源于网络,如有侵权,请联系删除!)列表模板上增加排序,myorder=hot注意,其中增加了一个虚拟字段myorder,这个字段后台并没有添加.他只是一个排序的标志符,需要最后排除掉.另外,模板上用到了{dede:php}标签,需要在后台系统设置.系统基本参

  

假如网站中,有一个价格字段trueprice,我希望根据价格从小到大,或从大到小进行点击筛选,或按热门,最新商品进行排序,效果图如下 

织梦列表页点击按价格按评分按更新按点击排序进行筛选方法

列表模板上增加排序,myorder=hot注意,其中增加了一个虚拟字段myorder,这个字段后台并没有添加.他只是一个排序的标志符,需要最后排除掉. 

另外,模板上用到了{dede:php}标签,需要在后台系统设置.系统基本参数,其它设置中,去掉对php模板标签的限制. 

模板如下

<a class="ib padding-right"  href="/plus/list.php?tid={dede:field.typeid/}&myorder=hot">{dede:php}if($_GET['myorder']=='hot'){echo '<span>最热</span>';}else{echo '最热';}{/dede:php}</a> <a class="ib padding-right" href="/plus/list.php?tid={dede:field.typeid/}&myorder=new">{dede:php}if($_GET['myorder']=='new'){echo '<span>最新</span>';}else{echo '最新';}{/dede:php}</a> <a class="ib padding-right" href="/plus/list.php?tid={dede:field.typeid/}&myorder=price_high">{dede:php}if($_GET['myorder']=='price_high'){echo '<span>价高</span>';}else{echo '价高';}{/dede:php}</a><a class="ib padding-right"href="/plus/list.php?tid={dede:field.typeid/}&myorder=price_low">{dede:php}if($_GET['myorder']=='price_low'){echo '<span>价低</span>';}else{echo '价低';}{/dede:php}</a>

首先,在自定义函数中includeextend.func.php增加非法过滤函数

/*字符过滤函数*/function snail_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+/" ,                      "/<(/?)( | |STYLE|HTML|HEAD|BODY|STYLE |i? |b|strong|style|html|img|P|o:p| |u|em|strike|BR|div|a|TABLE|TBODY| |tr|td|st1:chsdate|FONT|span|MARQUEE|body| |rn| | |?|%)([^>]*?)>/isU",           "/(<[^>]*)on[a-zA-Z]+s*=([^>]*>)/isU",          );        $tarr = array(" ",                      "",          "\1\2",          );         $str = preg_replace($farr, $tarr, $str);        $str = str_replace(               array( "<", ">", "'", """, ";", "/*", "*", "../", "./"),   array("&lt;","&gt;","","","","","","",""),   $str);    }    return $str;}

 

然后,在include/arc.listview.class.php里面增加排序判断及分页的定义,并排除myorder字段

一,修改CountRecord(),在第二行的下面 

在if(empty(cfgneedtypeid2))cfgneedtypeid2))cfg_need_typeid2 = ‘N’的下面

增加

//新增,多条件筛选 ,获得附加表的相关信息        $addtable  = $this->ChannelUnit->ChannelInfos['addtable'];        if($addtable!="")        {            $addJoin = " LEFT JOIN `$addtable` ON arc.id = ".$addtable.'.aid ';            $addField = '';            $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);            foreach($fields as $k=>$v)            {                $nfields[$v] = $k;            }            if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))            {                foreach($this->ChannelUnit->ChannelFields as $k=>$arr)                {                    if(isset($nfields[$k]))                    {                        if(!empty($arr['rename'])) {                            $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];                        }                        else {                            $addField .= ','.$addtable.'.'.$k;                        }                    }                }            }            if (isset($_REQUEST['tid'])){                $myget=$_GET;                unset($myget['myorder']);//删除一个字段                 //删除数组中的个别元素,活动状态,进行中,刚结束等,这些值是根据结束时间动态判断的,所以,数据库中并不存在,需要过滤掉这个sql查询条件                foreach($_GET as $key => $value) {                    //过滤掉不在$addtable表格中的字段,本次不负责处理                    //print_r($_GET);exit;                    $filtersql .= ($key!="q"&$key!="tid" && $key!="TotalResult" && $key!="PageNo") ? " AND $addtable.".snail_filter($key)." = '".snail_filter(urldecode($value))."'" : '';                }            }        }        else        {            $addField = '';            $addJoin = '';        }        //新增结束        //统计数据库记录

 

二、继续找到

$cquery = "SELECT COUNT(*) AS dd FROMdede_arctinyarc WHERE ".$this->addSql; 

修改为

$cquery = "SELECT COUNT(*) AS dd FROM `dede_arctiny` arc $addJoin WHERE ".$this->addSql.$filtersql;

 

三,替换函数function GetArcList()为全新的

function GetArcList($limitstart=0,$row=10,$col=1,$ len=30,$infolen=250,    $imgwidth=120,$imgheight=90,$listtype="all",$orderby="default",$innertext="",$tablewidth="100",$ismake=1,$orderWay='desc')    {        global $cfg_list_son;        $typeid=$this->TypeID;        if($row=='') $row = 10;        if($limitstart=='') $limitstart = 0;        if($ len=='') $ len = 100;        if($infolen=='') $infolen = 250;        if($imgwidth=='') $imgwidth = 120;        if($imgheight=='') $imgheight = 120;        if($listtype=='') $listtype = 'all';          if($orderWay=='') $orderWay = 'desc';        if($orderby=='') {            $orderby='default';        }        else {            $orderby=strtolower($orderby);        }        $tablewidth = str_replace('%','',$tablewidth);        if($tablewidth=='') $tablewidth=100;        if($col=='') $col=1;        $colWidth = ceil(100/$col);        $tablewidth = $tablewidth.'%';        $colWidth = $colWidth.'%';        $innertext = trim($innertext);        if($innertext=='') {            $innertext = GetSysTemplets('list_fulllist.htm');        }        //排序方式        $ordersql = '';        if($orderby=="senddate" || $orderby=="id") {            $ordersql=" order by arc.id $orderWay";        }        else if($orderby=="hot" || $orderby=="click") {            $ordersql = " order by arc.click $orderWay";        }        else if($orderby=="lastpost") {            $ordersql = "  order by arc.lastpost $orderWay";        }else if($orderby=="weight") {             $ordersql = "  order by arc.weight $orderWay";       }        else {            $ordersql=" order by arc.sortrank $orderWay";        }        //新增综合排序:默认 最热 最新 价高 价低         $addtable  = $this->ChannelUnit->ChannelInfos['addtable'];        if($_GET['myorder']=='默认'){                    $orderby='sortrank';                    $ordersql = "  order by arc.sortrank $orderWay";                }elseif($_GET['myorder']=='hot'){                    $orderby='hot';                   $ordersql = " order by arc.click $orderWay";                }                elseif($_GET['myorder']=='new'){                    $orderby='id';                    $ordersql = " order by arc.id $orderWay";                }                elseif($_GET['myorder']=='price_high'){                    $orderby='price_high';                    $ordersql = " order by ".$addtable.".price ".$orderWay;                }                elseif($_GET['myorder']=='price_low'){                    $orderby='price_low';                    $ordersql = " order by ".$addtable.".price asc";                }                 elseif($_GET['myorder']=='mian_high'){                    $orderby='mian_high';                    $ordersql = " order by ".$addtable.".mian ".$orderWay;                }                elseif($_GET['myorder']=='mian_low'){                    $orderby='mian_low';                    $ordersql = " order by ".$addtable.".mian asc";                }               else{                    $ordersql=" order by arc.id $orderWay";                }        //多条件查询新增,获得附加表的相关信息/        ////获得一个单列的文档列表继续        if($addtable!="")        {            $addJoin = " left join `$addtable` on arc.id = ".$addtable.'.aid ';            $addField = '';            $fields = explode(',',$this->ChannelUnit->ChannelInfos['listfields']);            foreach($fields as $k=>$v)            {                $nfields[$v] = $k;            }            if(is_array($this->ChannelUnit->ChannelFields) && !empty($this->ChannelUnit->ChannelFields))            {                foreach($this->ChannelUnit->ChannelFields as $k=>$arr)                {                    if(isset($nfields[$k]))                    {                        if(!empty($arr['rename'])) {                            $addField .= ','.$addtable.'.'.$k.' as '.$arr['rename'];                        }                        else {                            $addField .= ','.$addtable.'.'.$k;                        }                    }                }            }            if (isset($_REQUEST['tid'])){                $myget=$_GET;                unset($myget['myorder']);//删除一个字段            foreach($myget as $key => $value) {                    $mywhere=" AND $addtable.".snail_filter($key)." = '".snail_filter(urldecode($value))."'";                }                $filtersql .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? $mywhere : '';            }        }        else        {            $addField = '';            $addJoin = '';        }//print_r($addField);exit;//取出所有自定义字段      织梦6久阁模板网 //print_r($addJoin);exit;//left join `dede_addonarticle` on arc.id = dede_addonarticle.aid        //如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)        if(ereg('hot|click|lastpost|weight',$orderby))        {            $query = "Select arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,           tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath           $addField           from `dede_archives` arc           left join `dede_arctype` tp on arc.typeid=tp.id           $addJoin           WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row";        }        //普通情况先从arctiny表查出ID,然后按ID查询(速度非常快)        else        {            $t1 = ExecTime();            $ids = array();            $query = "SELECT id FROM `dede_arctiny` arc $addJoin WHERE {$this->addSql} $filtersql $ordersql LIMIT $limitstart,$row ";            //print_r($query);exit;//SELECT id FROM `dede_arctiny` arc left join `dede_addonarticle` on arc.id = dede_addonarticle.aid WHERE arc.arcrank > -1 And ( arc.typeid = '1' OR CONCAT(',', arc.typeid2, ',') like '%,1,%' ) AND dede_addonarticle.mystate = '即将开始' AND dede_addonarticle.mytype = '投资返现' order by arc.id desc LIMIT 0,16            $this->dsql->SetQuery($query);            $this->dsql->Execute();            //die(mysql_error());            while($arr=$this->dsql->GetArray())            {                $ids[] = $arr['id'];            }            //print_r($ids);exit;            $idstr = join(',',$ids);            //print_r($idstr);exit;//13,12,11,10,9,5,4 文章id串            if($idstr=='')            {                return '';            }            else            {                $query = "Select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,                    tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath                    $addField                    from `dede_archives` arc left join `dede_arctype` tp on arc.typeid=tp.id                    $addJoin                    where arc.id in($idstr) $ordersql ";            }            $t2 = ExecTime();            //echo $t2-$t1;        }        $this->dsql->SetQuery($query);        //print_r($query);exit;        //die(mysql_error());        $this->dsql->Execute('al');        $t2 = ExecTime();        //echo $t2-$t1;exit;        $artlist = '';        $this->dtp2->LoadSource($innertext);        $GLOBALS['autoindex'] = 0;        for($i=0;$i<$row;$i++)            //print_r($row);exit;调用条数20        {            if($col>1)            {                $artlist .= "<div>rn";            }            for($j=0;$j<$col;$j++)            {                if($row = $this->dsql->GetArray("al"))                    //print_r($row);exit;                {                    $GLOBALS['autoindex']++;                    $ids[$row['id']] = $row['id'];                    //处理一些特殊字段                    $row['infos'] = cn_substr($row['de ion'],$infolen);                    $row['id'] =  $row['id'];                    if($row['corank'] > 0 && $row['arcrank']==0)                    {                        $row['arcrank'] = $row['corank'];                    }                    $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row[' '],$row['ismake'],                    $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);                    $row['typeurl'] = GetTypeUrl($row['typeid'],MfTypedir($row['typedir']),$row['isdefault'],$row['defaultname'],                    $row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);                    if($row['litpic'] == '-' || $row['litpic'] == '')                    {                        $row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';                    }                    if(!eregi("^http://",$row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')                    {                        $row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];                    }                    $row['picname'] = $row['litpic'];                    $row['stime'] = GetDateMK($row['pubdate']);                    $row['type '] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";                    $row['image'] = "<img src='".$row['picname']."' border='0' width='$imgwidth' height='$imgheight' alt='".ereg_replace("['><]","",$row[' '])."'>";                    $row['img '] = "<a href='".$row['filename']."'>".$row['image']."</a>";                    $row['full '] = $row[' '];                    $row[' '] = cn_substr($row[' '],$ len);                    if($row['color']!='')                    {                        $row[' '] = "<font color='".$row['color']."'>".$row[' ']."</font>";                    }                    if(ereg('c',$row['flag']))                    {                        $row[' '] = "".$row[' ']."";                    }                    $row['text '] = "<a href='".$row['filename']."'>".$row[' ']."</a>";                    $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];                    $row['memberurl'] = $GLOBALS['cfg_memberurl'];                    $row['templeturl'] = $GLOBALS['cfg_templeturl'];                    //编译附加表里的数据                    foreach($row as $k=>$v)                    {                        $row[strtolower($k)] = $v;                    }                    foreach($this->ChannelUnit->ChannelFields as $k=>$arr)                    {                        if(isset($row[$k]))                        {                            $row[$k] = $this->ChannelUnit->MakeField($k,$row[$k]);                        }                    }                    if(is_array($this->dtp2->CTags))                    {                        foreach($this->dtp2->CTags as $k=>$ctag)                        {                            //print_r($this->dtp2->CTags);exit;所有字段名                            if($ctag->GetName()=='array')                            {                                //传递整个数组,在runphp模式中有特殊作用                                $this->dtp2->Assign($k,$row);                            }                            else                            {                                if(isset($row[$ctag->GetName()]))                                {                                    $this->dtp2->Assign($k,$row[$ctag->GetName()]);                                }                                else                                {                                    $this->dtp2->Assign($k,'');                                }                            }                        }                    }if($row['myendtime']!=''){                    if($row['myendtime']<time()){//已结束的活动                    $artlist2 .= $this->dtp2->GetResult();                }else{                    $artlist1 .= $this->dtp2->GetResult();                    }                    $artlist=$artlist1.$artlist2;                    }else{                    $artlist .= $this->dtp2->GetResult();                    }                    //$i2=$i2+1;                    //print_r($i2);                }//if hasRow//exit;            }//Loop Col//print_r($col);exit;            if($col>1)            {                $i += $col - 1;                $artlist .= "  </div>rn";            }            $row2[] = $row;        }//Loop Line//print_r($row2);exit;        $t3 = ExecTime();        //echo ($t3-$t2);        $this->dsql->FreeResult('al');        //die(mysql_error());        return $artlist;    }

 

四,动态分页函数整体替换为

//获取动态的分页列表    function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno",$pagelang)    {    /*****************************************************************************************/                     if($pagelang=='cn'){                          $uahome="首页";                          $uaprevious="?";                          $uanext="?";                          $ualastpage="末页";                          $uapage="页";                          $uatotal="共";                          $uarecords="条记录";                       }else{                          $uahome=" Home ";                          $uaprevious=" Previous ";                          $uanext=" Next ";                          $ualastpage=" Last Page ";                          $uapage=" Page ";                          $uatotal=" Total ";                          $uarecords=" Records. ";                        }        global $cfg_rewrite;        $prepage = $nextpage = '';        $prepagenum = $this->PageNo-1;        $nextpagenum = $this->PageNo+1;        if($list_len=='' || ereg("[^0-9]",$list_len))        {            $list_len=3;        }        $totalpage = ceil($this->TotalResult/$this->PageSize);        if($totalpage<=1 && $this->TotalResult>0)        {            return "</ul><ul class="margin pagination border-main pageinfo"><li><a >".$uatotal." 1 ".$uapage."/".$this->TotalResult."".$uarecords."</a></li>rn";        }        if($this->TotalResult == 0)        {            return "</ul><ul class="margin pagination border-main pageinfo"><li><a >".$uatotal." 0 ".$uapage."/".$this->TotalResult."".$uarecords."</a></li>rn";        }        $maininfo = "</ul><ul class="margin pagination border-main pageinfo"><li><a >".$uatotal." <strong>{$totalpage}</strong>".$uapage."<strong>".$this->TotalResult."</strong>".$uarecords."</a></li>rn";        $purl = $this->GetCurUrl();        if($cfg_rewrite == 'Y')        {            $nowurls = ereg_replace("-", ".php?", $purl);            $nowurls = explode("?", $nowurls);            $purl = $nowurls[0];        }        $geturl = "tid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";        $purl .= '?'.$geturl;        $optionlist = '';        //$hidenform = "<input type='hidden' name='tid' value='".$this->TypeID."'>rn";        //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>rn";//获取筛选参数        foreach($_GET as $key => $value) {            $pageaddurl .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? "&".snail_filter($key)."=".snail_filter($value) : '';        }        //获得?和?的链接        if($this->PageNo != 1)         {            $prepage.="<li><a href='".$purl."PageNo=$prepagenum".$pageaddurl."'>".$uaprevious."</a></li>rn";            $indexpage="<li><a href='".$purl."PageNo=1".$pageaddurl."'>".$uahome."</a></li>rn";        }        else        {            $indexpage="<li><a>".$uahome."</a></li>rn";        }        if($this->PageNo!=$totalpage && $totalpage>1)        {            $nextpage.="<li><a href='".$purl."PageNo=$nextpagenum".$pageaddurl."'>".$uanext."</a></li>rn";            $endpage="<li><a href='".$purl."PageNo=$totalpage".$pageaddurl."'>".$ualastpage."</a></li>rn";        }        else        {            $endpage="<li><a>".$ualastpage."</a></li>rn";        }        //获得数字链接        $listdd="";        $total_list = $list_len * 2 + 1;        if($this->PageNo >= $total_list)        {            $j = $this->PageNo-$list_len;            $total_list = $this->PageNo+$list_len;            if($total_list>$totalpage)            {                $total_list=$totalpage;            }        }        else        {            $j=1;            if($total_list>$totalpage)            {                $total_list=$totalpage;            }        }        for($j;$j<=$total_list;$j++)        {            if($j==$this->PageNo)            {                $listdd.= "<li class="active pagenum"><a>$j</a></li>rn";            }            else            {                $listdd.="<li class="pagenum"><a href='".$purl."PageNo=$j".$pageaddurl."'>".$j."</a></li>rn";            }        }        $plist = '';        if(eregi('index',$listitem)) $plist .= $indexpage;        if(eregi('pre',$listitem)) $plist .= $prepage;        if(eregi('pageno',$listitem)) $plist .= $listdd;        if(eregi('next',$listitem)) $plist .= $nextpage;        if(eregi('end',$listitem)) $plist .= $endpage;        if(eregi('option',$listitem)) $plist .= $optionlist;        if(eregi('info',$listitem)) $plist .= $maininfo;        if($cfg_rewrite == 'Y')        {            $plist = str_replace('.php?tid=', '-', $plist);            $plist = str_replace('&TotalResult=', '-', $plist);            $plist = preg_replace("/&PageNo=(d+)/i",'-\1.html',$plist);        }        return $plist;    }

下载链接:网站源码/小程序源码/网站模板下载

Tags: 织梦 方法 价格 列表 更新