在以往的多次文章中提到,likeart和likearticle是不同的,likeartcle标签默认是不支持order by属性的(包括V5.7),在模板团找到了修改的方法:
编辑likearticle.lib.php文件,首先获得标签传递过来的orderby的属性值,找到:
extract($ctag->CAttribute->Items, EXTR_SKIP);
$revalue =";
在下面添加:
$orderby=$ctag->GetAtt(‘orderby’);
在源代码中找到下面代码:
if( empty($arcid) || $byabs==0 )
{
$orderquery = " ORDER BY arc.id desc ";
}
else {
$orderquery = " ORDER BY ABS(arc.id - ".$arcid.") ";
}
这是likearticle标签默认的排序方式。赋予标签orderby属性那么这段代码就没意义了,把上面代码替换为(注意将中文状态的单引号'改为英文状态,否则实现不了):
$orderquery = '';
if($orderby=='hot' || $orderby=='click') $orderquery = " order by arc.click $orderWay ";
else if($orderby == 'sortrank' || $orderby=='pubdate') $orderquery = " order by arc.sortrank $orderWay";
else if($orderby == 'id') $orderquery = " order by arc.id $orderWay";
else if($orderby == 'near') $orderquery = " order by ABS(arc.id – ".$arcid.")";
else if($orderby == 'lastpost') $orderquery = " order by arc.lastpost $orderWay";
else if($orderby == 'scores') $orderquery = " order by arc.scores $orderWay";
else if($orderby == 'rand') $orderquery = " order by rand()";
else if($orderby == 'weight') $orderquery = " order by arc.weight asc";//如果没有特定设置排序则按照权重先排序
else $orderquery = " order by arc.sortrank $orderWay";
这样一来就为likearticle增加了orderby属性功能,系统调用的是当前栏目的相关文章。