织梦cms让文章按权重排序
首先,我们打开include\taglib下的文件arclist.lib.php ,在代码的第74-75行, 找到:
$isweight = $ctag->GetAtt('isweight');
把这行修改为:
$weight = $ctag->GetAtt('weight');
然后在大约在327行找到,
//文档排序的方式
$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 == 'scores') $ordersql = " ORDER BY arc.scores $orderWay";
else if($orderby == 'rand') $ordersql = " ORDER BY rand()";
else if($orderby == 'weight') $ordersql = " order by arc.weight asc";//插入这句 从小到大
else $ordersql = " ORDER BY arc.sortrank $orderWay";
添加红色代码那一段,改好之后,dede:arclist中就可以按权重来排序了。
但是我们在栏目列表页使用dede:list还是无法按权限排序。这是因为dede:list标签并没有加入按weight排序的方法。
//排序方式
$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";
}
在第778行处找到此段代码(红色部分为要添加的代码):
//如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)
if(preg_match('/hot|click|lastpost|weight/', $orderby))
include\taglib下的文件arclist.lib.php和include下面的arc.listview.class.php这两个文件修改好了之后,就可以通过:
{dede:list orderby='weight' orderway='asc'} 和 {dede:arclist orderby='weight' orderway='asc'}
来对文章或者产品进行权重排序了~