dedecms列表页实现文档按权重weight排序
1、调用 {dede:list pagesize='12′ orderby='weight' isweight='Y' orderway='desc'}
2、dedecms列表页文章按权重排序无效问题,找到list解析文件include/arc.listview.class.php,发现排序规则里面并没有按照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";
}
3、//如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
if(preg_match('/hot|click|lastpost|weight/', $orderby))
dede:arclist按权重排序的修改方法
再改一个地方:/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";
2、
大约在74 、75行找到:
// arclist是否需要weight排序,默认为"N",如果需要排序则设置为"Y"
$isweight = $ctag->GetAtt('isweight');
把这行修改为:
$weight = $ctag->GetAtt('weight');
或者: 修改 170行 $isweight='N' 的值为Y
调用:
{dede:arclist typeid='32' pagesize='20' isweight='Y' orderby='weight' orderway='desc'}
orderby='weight' orderway='desc'
备注 //desc 从大到小和asc 从小到大