Zblog資源類主題模板涉及的接口較多,而且目前上線的主題中基本都有一個(gè)常用的功能,那就是分類模板頁(yè)的排序,可以自由組合,按照時(shí)間、瀏覽、評(píng)論等等,部分主題模板還可能設(shè)計(jì)了免費(fèi)、收費(fèi)、VIP等等功能,所以這個(gè)排序是必要的。參考了百度和幾位朋友的介紹算是實(shí)現(xiàn)了,但是跟可風(fēng)大佬聊天的時(shí)候順帶說(shuō)了這個(gè)事,因?yàn)檗┏醯呐判蛴幸徊糠执a是可風(fēng)寫(xiě)的,然后大佬告訴我有更簡(jiǎn)介高效的代碼,好吧,有技術(shù)就是任性,不多說(shuō),直接上代碼。
首先掛載接口
需要在主題核心文件(include.php)中掛載接口
Add_Filter_Plugin(&39;Filter_Plugin_LargeData_Article&39;,&39;LargeData_Article&39;);
然后接口對(duì)應(yīng)代碼:
//分類模板排序 functionLargeData_Article($select,$w,&$order,$limit,$option,$type){ global$zbp; switch($type){ case&39;category&39;: //分類模板標(biāo)簽,此段可刪除 case&39;tag&39;: //標(biāo)簽?zāi)0鍢?biāo)簽,此段可刪除 $pagebar=$option[&39;pagebar&39;]; $sort=GetVars(&39;sort&39;,&39;GET&39;)?&39;ASC&39;:&39;DESC&39;; switch($o=GetVars(&39;order&39;,&39;GET&39;)){ case&39;view&39;: $order=array(&39;log_ViewNums&39;=>$sort); break; case&39;comment&39;: $order=array(&39;log_CommNums&39;=>$sort); break; case&39;newest&39;: default: $order=array(&39;log_PostTime&39;=>$sort); $sort==&39;DESC&39;&&$o=null; break; } if($o){ $pagebar->UrlRule->__construct($zbp->option[&39;ZC_CATEGORY_REGEX&39;].($zbp->Config(&39;system&39;)->ZC_STATIC_MODE!=&39;REWRITE&39;?&39;&&39;:&39;?&39;).&39;order={%order%}&sort={%sort%}&39;); $pagebar->UrlRule->Rules[&39;{%order%}&39;]=$o; $pagebar->UrlRule->Rules[&39;{%sort%}&39;]=(int)GetVars(&39;sort&39;,&39;GET&39;); } break; } }
其次在模板添加代碼:
找到主題分類模板(catalog.php)文件,在適當(dāng)?shù)奈恢眉尤肱判虼a:
<formid="sort-list"class="filter-tag"> <spanclass="filter-l"><iclass="iconfont-paixu"></i>排序</span> <liclass="filterorder"> <ahref=""rel="nofollow"class="{ifGetVars(&39;order&39;,&39;GET&39;)==&39;newest&39;||!GetVars(&39;order&39;,&39;GET&39;)}current{/if}"data-type="newest">蕞新<iclass="iconfont-chevron-{ifGetVars(&39;sort&39;,&39;GET&39;)}up{else}down{/if}"></i></a> <ahref=""rel="nofollow"class="{ifGetVars(&39;order&39;,&39;GET&39;)==&39;view&39;}current{/if}"data-type="view">瀏覽<iclass="iconfont-chevron-{ifGetVars(&39;sort&39;,&39;GET&39;)}up{else}down{/if}"></i></a> <ahref=""rel="nofollow"class="{ifGetVars(&39;order&39;,&39;GET&39;)==&39;comment&39;}current{/if}"data-type="comment">評(píng)論<iclass="iconfont-chevron-{ifGetVars(&39;sort&39;,&39;GET&39;)}up{else}down{/if}"></i></a></li> {if$zbp->Config(&39;system&39;)->ZC_STATIC_MODE!=&39;REWRITE&39;}<inputtype="hidden"name="cate"value="{$category->ID}">{/if} <inputtype="hidden"name="order"value="{GetVars(&39;order&39;,&39;GET&39;)}"> <inputtype="hidden"name="sort"value="{php}echo(int)GetVars(&39;sort&39;,&39;GET&39;){/php}"> </form>
添加之后css樣式自己修改,圖標(biāo)采用的是阿里圖標(biāo)庫(kù),如果您的奧森圖標(biāo)或者其他請(qǐng)自行更改<i class="icon font-paixu"></i>代碼,值得注意的是 name="cate" 默認(rèn)是指分類模板,如果是標(biāo)簽?zāi)0屙?yè)需要修改成 name="tags" 就可以了。
蕞后添加js代碼:
找到主題模板自帶的js文件,在蕞后的位置添加如下代碼,如果是放在html里,記得首位加上<script>如下代碼</script>
//分類排序 !function(f){ vara=f.find(&39;.ordera&39;),o=f.find(&39;[name=order]&39;),s=f.find(&39;[name=sort]&39;); a.click(function(){ varv=$(this).data(&39;type&39;); if(v===o.val()){ s.val(s.val().toString()===&39;1&39;?0:1); }else{ s.val(&39;&39;===o.val()&&!$(this).index()?1:0); o.val(v); } f.submit(); returnfalse; }) }($(&39;sort-list&39;))
效果如開(kāi)篇的圖,大功告成。
來(lái)源:李洋博客
關(guān)注微信號(hào)和抖音號(hào)