百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>destoon教程> destoon教程之列表页实现自定义挑选
分享文章到:

destoon教程之列表页实现自定义挑选

发布时间:08/25 来源:未知 浏览: 关键词:

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

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


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

<script>
function getQueryString(){
var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g"));
if(result == null){
return "";
}
for(var i = 0; i < result.length; i++){
result[i] = result[i].substrin(1);
}
return result;
}

function goSort(name,value){
var string_array = getQueryString();
var oldUrl = (document.URL.indexOf("index.php")==-1)?document.URL+"index.php":document.URL;
var newUrl;
if(string_array.length>0)//假如已经有挑选前提
{ var repeatField = false;
for(var i=0;i<string_array.length;i++){
if(!(string_array[i].indexOf(name)==-1)){
repeatField = true;//假如有反复挑选前提,更换前提值
newUrl = oldUrl.replac(string_array[i],name+"="+value);
}
}

//假如没有反复的挑选字段
if(repeatField == false){
newUrl = oldUrl+"&"+name+"="+value;
}

}else{//假如还没有挑选前提
newUrl = oldUrl+"?"+name+"="+value;
}

//跳转
window.location = newUrl;
}


function setSelected(name,value){
var all_li = $("#"+name).find("a");
//清除所有a标签的now类
all_li.each(function(){
$(this).removeClass("now");
});
//为选中的a增添now类
all_li.eq(value).addClass("now");
}

$(document).ready(function(){
var string_array = getQueryString();
for(var i=0;i<string_array.length;i++){
var tempArr = string_array[i].split("=");
setSelected(tempArr[0],tempArr[1]);//设定选中的挑选前提
}
});
</script>

然后在模板中引入前提语句,这下面的是挑选前提,看不懂的先学学,参照 修改。

{php $condition = "status=3";}
{php $dmode = array('',1=>" and price=0",2=>" and price>0");}
{php $dcatid = array('',1=>" and catid=10",2=>" and catid=11");}
{php $dprice = array('',1=>" and price<1001",2=>" and price>1000 and price<2000",
3=>" and price>2001 and price<3000",4=>" and price>3001 and price<5000",5=>" and and price>5001 and price<10001",6=>" and price>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]";}

挑选模板,仅供参照

<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="java script:goSort('mode',0);">全部</a>
<a href="java script:goSort('mode',1);">商业模板</a>
<a href="java script: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="java script:goSort('catid',0);">全部</a>
<a href="java script:goSort('catid',1);">平台型</a>
<a href="java script: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="java script:goSort('price',0);">全部</a></li>
<li> <a href="java script:goSort('price',1);">1000以下</a></li>
<li><a href="java script:goSort('price',2);">1000-2000</a></li>
<li> <a href="java script:goSort('price',3);">2000-3000</a></li>
<li> <a href="java script:goSort('price',4);">3000-5000</a></li>
<li> <a href="java script:goSort('price',5);">5000-10000</a></li>
<li> <a href="java script: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="java script:goSort('order',0);">新品</a>
<a rel="nofollow" href="java script:goSort('order',1);">价钱</a>
<a rel="nofollow" href="java script:goSort('order',2);">热销</a>
</span>

</div>

</div>

轮回语句中&condition=后面参加上$condition

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板