平时我们有时会发现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'}