zblog分类页实现排序的方法
这里只提供代码,没有代码具体的说明,请自行研究
挂载接口 Filter_Plugin_LargeData_Article
function LargeData_Article($select, $w, &$order, $limit, $option, $type){ global $zbp; switch($type){ case 'category': $pagebar = $option['pagebar']; $sort = GetVars('sort','GET') ? 'ASC' : 'DESC'; switch($o = GetVars('order','GET')){ case 'view': $order = array('log_ViewNums' => $sort); break; case 'comment': $order = array('log_CommNums' => $sort); break; case 'newest': default: $order = array('log_PostTime' => $sort); $sort == 'DESC' && $o = null; break; } if ($o){ $pagebar->UrlRule->__construct($zbp->option['ZC_CATEGORY_REGEX'] .($zbp->Config('system')->ZC_STATIC_MODE != 'REWRITE' ? '&' : '?'). 'order={%order%}&sort={%sort%}'); $pagebar->UrlRule->Rules['{%order%}'] = $o; $pagebar->UrlRule->Rules['{%sort%}'] = (int)GetVars('sort','GET'); } break; } }
模板代码:
<form id="kf-order"> <div class="filter order"> <a href="" rel="nofollow" class="{if GetVars('order','GET') == 'newest' || !GetVars('order','GET')}active{/if}" data-type="newest">最新<i class="icon icon-arrow-{if GetVars('sort','GET')}up{else}down{/if}"></i></a> <a href="" rel="nofollow" class="{if GetVars('order','GET') == 'view'}active{/if}" data-type="view">浏览<i class="icon icon-arrow-{if GetVars('sort','GET')}up{else}down{/if}"></i></a> <a href="" rel="nofollow" class="{if GetVars('order','GET') == 'comment'}active{/if}" data-type="comment">评论<i class="icon icon-arrow-{if GetVars('sort','GET')}up{else}down{/if}"></i></a> </div> {if $zbp->Config('system')->ZC_STATIC_MODE != 'REWRITE'}<input type="hidden" name="cate" value="{$category->ID}">{/if} <input type="hidden" name="order" value="{GetVars('order','GET')}"> <input type="hidden" name="sort" value="{php}echo (int)GetVars('sort','GET'){/php}"> </form>
js代码:
!function(f){ var a=f.find('.order a'),o=f.find('[name=order]'),s=f.find('[name=sort]'); a.click(function(){ var v=$(this).data('type'); if(v===o.val()){ s.val(s.val().toString()==='1'?0:1); }else{ s.val(''===o.val() && !$(this).index() ? 1 : 0); o.val(v); } f.submit(); return false; }) }($('#kf-order'))