dedecms的list標(biāo)簽orderby屬性只支持按一個字段排序,假如想多個字段排序的話,就需要對PHP舉辦修改,使其可以支持多字段排序,修改如下:
打開include/arc.listview.class.php,找到:
//假如不消默認(rèn)的sortrank或id排序,利用連系查詢(數(shù)據(jù)量大時很是遲鈍) if(preg_match('/hot|click|lastpost|title/', $orderby)) { $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id $addJoin WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row"; } //普通環(huán)境先從arctiny表查出ID,然后按ID查詢(速度很是快) else { $t1 = ExecTime(); $ids = array(); $query = "SELECT id FROM `js_arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row "; $this->dsql->SetQuery($query); $this->dsql->Execute(); while($arr=$this->dsql->GetArray()) { $ids[] = $arr['id']; } $idstr = join(',',$ids); if($idstr=='') { return ''; } else { $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id $addJoin WHERE arc.id in($idstr) $ordersql "; } $t2 = ExecTime(); //echo $t2-$t1; }
替換為:
if($orderby=="default") { $t1 = ExecTime(); $ids = array(); $query = "SELECT id FROM `js_arctiny` arc WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row "; $this->dsql->SetQuery($query); $this->dsql->Execute(); while($arr=$this->dsql->GetArray()) { $ids[] = $arr['id']; } $idstr = join(',',$ids); if($idstr=='') { return ''; } else { $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id $addJoin WHERE arc.id in($idstr) $ordersql "; } $t2 = ExecTime(); //echo $t2-$t1; } else { $query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM `js_archives` arc LEFT JOIN `js_arctype` tp ON arc.typeid=tp.id $addJoin WHERE {$this->addSql} $ordersql LIMIT $limitstart,$row"; }
找到:
else { $ordersql=" ORDER BY arc.sortrank $orderWay"; }
替換為:
else if($orderby=="default"){ $ordersql=" ORDER BY arc.sortrank $orderWay"; } else{ $ordersql=" ORDER BY ".$orderby.",arc.sortrank $orderWay"; }
此刻在模板中就可以應(yīng)用了多字段排序了,模板應(yīng)用如下:
{dede:list pagesize='17' orderby='arc.title desc,arc.id'}
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: DEDECMS給list標(biāo)簽加上多字段排序功能