织梦默认情况下是没有开启weight排序的需要修改arclist.lib.php
1、 在织梦系统中找到以下目录\include\taglib中的arclist.lib.php文件并打开
大约在74 、75行找到:
// arclist是否需要weight排序,默认为"N",如果需要排序则设置为"Y"
$isweight = $ctag->GetAtt('isweight');
把这行修改为:
$weight = $ctag->GetAtt('weight');
2、
大约在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 row='10' orderby='weight'}时一切正常,但进入到栏目列表则失效了,一看代码呈现的规则是{dede:list pagesize='10' orderby='weight'}与首页不一致
找了半天终于找到了解决方法:
找到list解析文件include/arc.listview.class.php
//排序方式
$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";
} 发现排序规则里面并没有按照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";
} 更改好在后台更新栏目html,新问题又来了,更新报错
Error infos: Unknown column 'arc.weight' in 'order clause'
Error sql: Select id From `dede_arctiny` arc where arc.arcrank > -1 And ( arc.typeid = '10' OR CONCAT(',', arc.typeid2, ',') like '%,10,%' ) order by arc.weight desc limit 0,10
根据错误信息查找代码,很快找到include/arc.listview.class.php第669行 为报错的sql语句,通过检查发现原来排序有两种查询,一个是单表查询一个是组合查询,而我们按weight排序需要进行组合查询,而进入组合查询的条件没有包含weight,修改条件if(preg_match('/hot|click|lastpost',$orderby/))为if(preg_match('/hot|click|lastpost|weight',$orderby/)),这句代码就在大概654行左右,保存文件更新
OK,再更新栏目页面试试,可以排序了吧,不过要注意的是更改后不是按后台的提示"越小越靠前",而是"越大越靠前",如果你需要越小越靠前的话,调用的时候改为{dede:list pagesize='10' orderby='weight' orderway="asc"}就行了,估计这是织梦dedecms遗漏的地方,希望在新版本中解决。