栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > dedecms

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

dedecms 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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

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

模板如下

{dede:php}if($_GET['myorder']=='hot'){echo '最热';}else{echo '最热';}{/dede:php}
 {dede:php}if($_GET['myorder']=='new'){echo '最新';}else{echo '最新';}{/dede:php}
 {dede:php}if($_GET['myorder']=='price_high'){echo '价高';}else{echo '价高';}{/dede:php}
{dede:php}if($_GET['myorder']=='price_low'){echo '价低';}else{echo '价低';}{/dede:php}

首先,在自定义函数中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", "'", "
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 "
  • ".$uatotal." 1 ".$uapage."/".$this->TotalResult."".$uarecords."
  • rn"; } if($this->TotalResult == 0) { return "
  • ".$uatotal." 0 ".$uapage."/".$this->TotalResult."".$uarecords."
  • rn"; } $maininfo = "
  • ".$uatotal." {$totalpage}".$uapage."".$this->TotalResult."".$uarecords."
  • 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 = "rn"; //$hidenform .= "rn"; //获取筛选参数 foreach($_GET as $key => $value) { $pageaddurl .= ($key!="tid" && $key!="TotalResult" && $key!="PageNo") ? "&".snail_filter($key)."=".snail_filter($value) : ''; } //获得?和?的链接 if($this->PageNo != 1) { $prepage.="
  • ".$uaprevious."
  • rn"; $indexpage="
  • ".$uahome."
  • rn"; } else { $indexpage="
  • ".$uahome."
  • rn"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="
  • ".$uanext."
  • rn"; $endpage="
  • ".$ualastpage."
  • rn"; } else { $endpage="
  • ".$ualastpage."
  • 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.= "
  • $j
  • rn"; } else { $listdd.="
  • ".$j."
  • 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; }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/5105.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号