平時我們有時會發現dedecms列表頁文章按權重排序無效問題,找到list解析文件include/arc.listview.class.ph,發現排序規則里面並沒有按照weight排序的判斷,於是乎修改程序加入排序規則,大概在771行,加入下面紅色代碼
//排序方式
$ordersql = '';
if($orderby=="senddate" || $orderby=="id") {
$ordersql=" order by arc.id $orderWay";
}
else if($orderby=="hot" || $orderby=="click") {
$ordersql = " order by arc.click $orderWay";
}
else if($orderby=="lastpost") {
$ordersql = " order by arc.lastpost $orderWay";
}
else if($orderby=="weight") {
$ordersql = " order by arc.weight $orderWay";
}
else {
$ordersql=" order by arc.sortrank $orderWay";
}
同時修改條件,在812行左右,加入|weight參數
//如果不用默認的sortrank或id排序,使用聯合查詢(數據量大時非常緩慢) if(preg_match('/hot|click|lastpost|weight/', $orderby))
有的朋友反映說改了不能用,再改一個地方:/include/taglib/arclist.lib.php加入紅色的語句
//文檔排序的方式
$ordersql = '';
if($orderby=='hot' || $orderby=='click') $ordersql = " ORDER BY arc.click $orderWay";
else if($orderby == 'sortrank' || $orderby=='pubdate') $ordersql = " ORDER BY arc.sortrank $orderWay";
else if($orderby == 'id') $ordersql = " ORDER BY arc.id $orderWay";
else if($orderby == 'near') $ordersql = " ORDER BY ABS(arc.id - ".$arcid.")";
else if($orderby == 'lastpost') $ordersql = " ORDER BY arc.lastpost $orderWay";
else if($orderby == 'weight') $ordersql = " ORDER BY arc.weight $orderWay";
else if($orderby == 'scores') $ordersql = " ORDER BY arc.scores $orderWay";
//功能:增加按好評數和差評數調用
else if($orderby == 'goodpost') $ordersql = " order by arc.goodpost $orderWay";
else if($orderby == 'badpost') $ordersql = " order by arc.badpost $orderWay";
else if($orderby == 'rand') $ordersql = " ORDER BY rand()";
else $ordersql = " ORDER BY arc.sortrank $orderWay";
arclist 對weight的排序也不准確,在模板調用時,需要加上一個isweight的屬性,如下紅色代碼
{dede:arclist typeid='32' pagesize='20' isweight='Y' orderby='weight' orderway='asc'}