假如网站中,有一个价格字段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;
}
|