宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

任何页面实现自定义筛选,不二开内核文件,全部在模板中实现,不影响升级,不使用搜索功能。

首页在页头引入jquery.min.js 文件,默认的模板是有这个的。如果不是默认的模板,也没这个文件,请去下载个。

然后在筛选的页面引入以下JS代码:

[php]
<script>
function getQueryString){
var result = location.search.matchnew RegExp"[\?\&][^\?\&]+=[^\?\&]+","g"));
ifresult == null){
return "";
}
forvar i = 0; i < result.length; i++){
result[i] = result[i].substrin1);
}
return result;
}

function goSortname,value){
var string_array = getQueryString);
var oldUrl = document.URL.indexOf"index.php")==-1)?document.URL+"index.php":document.URL;
var newUrl;
ifstring_array.length>0)//如果已经有筛选条件
{ var repeatField = false;
forvar i=0;i<string_array.length;i++){
if!string_array[i].indexOfname)==-1)){
repeatField = true;//如果有重复筛选条件,替换条件值
newUrl = oldUrl.replacstring_array[i],name+"="+value);
}
}

//如果没有重复的筛选字段
ifrepeatField == false){
newUrl = oldUrl+"&"+name+"="+value;
}

}else{//如果还没有筛选条件
newUrl = oldUrl+"?"+name+"="+value;
}

//跳转
window.location = newUrl;
}

function setSelectedname,value){
var all_li = $"#"+name).find"a");
//清除所有a标签的now类
all_li.eachfunction){
$this).removeClass"now");
});
//为选中的a增加now类
all_li.eqvalue).addClass"now");
}

$document).readyfunction){
var string_array = getQueryString);
forvar i=0;i<string_array.length;i++){
var tempArr = string_array[i].split"=");
setSelectedtempArr[0],tempArr[1]);//设置选中的筛选条件
}
});
</script>
[/php]

然后在模板中引入条件语句,这下面的是筛选条件,看不懂的先学学,参考修改。

[php]
{php $condition = "status=3";}
{php $dmode = array”,1=&gt;" and price=0",2=&gt;" and price&gt;0");}
{php $dcatid = array”,1=&gt;" and catid=10",2=&gt;" and catid=11");}
{php $dprice = array”,1=&gt;" and price&lt;1001",2=&gt;" and price&gt;1000 and price&lt;2000",3=&gt;" and price&gt;2001 and price&lt;3000",4=&gt;" and price&gt;3001 and price&lt;5000",5=&gt;" and and price&gt;5001 and price&lt;10001",6=&gt;" and price&gt;10000");}
{php $order = isset$order) ? intval$order) : 0;}
{php $mode = isset$mode) ? intval$mode) : 0;}
{php $dorder = array’addtime desc’,’price desc’,’hits desc’);}
{php $condition.= $dmode[$mode];}
{php $condition.= $dcatid[$catid];}
{php $condition.= $dprice[$price];}
{php $condition.=" order by $dorder[$order]";}
[/php]

筛选模板,仅供参考

[php]
<div class="left j-left wfs fz12">
<h3 class="template">收费模式<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs" id="mode">
<a class="now" href="javascript:goSort’mode’,0);">全部</a>
<a href="javascript:goSort’mode’,1);">商业模板</a>
<a href="javascript:goSort’mode’,2);">免费模板</a>
</div>
<h3 class="template">模板类型<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs" id="catid">
<a class="now" href="javascript:goSort’catid’,0);">全部</a>
<a href="javascript:goSort’catid’,1);">平台型</a>
<a href="javascript:goSort’catid’,2);">小众型</a>
</div>
<h3 class="template">价格<span class="hide-left j-hide-left" style=""><i></i></span></h3>
<div class="icons j-icons wfs price" id="price">
<li> <a class="now" href="javascript:goSort’price’,0);">全部</a></li>
<li> <a href="javascript:goSort’price’,1);">1000以下</a></li>
<li><a href="javascript:goSort’price’,2);">1000-2000</a></li>
<li> <a href="javascript:goSort’price’,3);">2000-3000</a></li>
<li> <a href="javascript:goSort’price’,4);">3000-5000</a></li>
<li> <a href="javascript:goSort’price’,5);">5000-10000</a></li>
<li> <a href="javascript:goSort’price’,6);">10000以上</a></li>
</div>

</div>

</div>

<div class="right j-right" style="margin-left: 300px;">
<div class="sort wfs">
<div style="float:left;">
<span style="margin-left:45px; float:left; padding-top:5px; font-size:12px;">排序:</span>

<span class="sort-icons j-sort-icons" id="order">
<a class="now" rel="nofollow" href="javascript:goSort’order’,0);">新品</a>
<a rel="nofollow" href="javascript:goSort’order’,1);">价格</a>
<a rel="nofollow" href="javascript:goSort’order’,2);">热销</a>
</span>

</div>

</div>
[/php]

循环语句中&condition=后面加入上$condition
大功 告成。

转自:http://www.dtmoban.com/Course/5/3.html