我們在使用DedeCMS用于圖片站W(wǎng)EB開發(fā)時(shí),需要隨機(jī)調(diào)用文章、圖集和關(guān)聯(lián)文章、圖集功能,以增加用戶黏度,這個(gè)也屬于站內(nèi)優(yōu)化重要一部分。
一般用標(biāo)簽調(diào)用都有排序orderby,默認(rèn)的排序主要有:
orderby='sortrank' 文檔排序方式
orderby='hot' 或 orderby='click' 表示按點(diǎn)擊數(shù)排列
orderby='sortrank' 或 orderby='pubdate' 按出版時(shí)間排列
orderby='near'
orderby='lastpost' 按最后評論時(shí)間
orderby='scores' 按得分排序
orderby='id' 按文章ID排序
orderby='rand' 隨機(jī)獲得指定條件的文檔列表
但是調(diào)用文章相關(guān)文章標(biāo)簽{dede:likearticle}卻沒有orderby這個(gè)功能。今天我們想給likearticle也增加一個(gè)排序功能.
方法也很簡單,打開/include/taglib/likearticle.lib.php,找到以下代碼(大概在第97行):
if( empty($arcid) || $byabs==0 ) {
$orderquery = " order by arc.id desc ";
}
else {
$orderquery = " order by ABS(arc.id - ".$arcid.") ";
}
修改為:
if($orderby=='hot' || $orderby=='click') $orderquery = " order by arc.click $orderWay";
else if($orderby == 'sortrank' || $orderby=='pubdate') $orderquery = " orderby 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";
保存后,再在{dede:likearticle}標(biāo)簽中增加orderby的值即可實(shí)現(xiàn)按增加需要的方式進(jìn)行排序