織夢(mèng)用于圖片站W(wǎng)EB開(kāi)發(fā)時(shí),需要隨機(jī)調(diào)用文章、圖集和關(guān)聯(lián)文章、圖集功能,以增加用戶黏度,屬于站內(nèi)優(yōu)化重要一部分。一般用標(biāo)簽調(diào)用都有排序orderby,默認(rèn)的排序主要有
{dede:arclist orderby=''}
[field:title/]
{/dede:arclist}
orderby='sortrank' 文檔排序方式
orderby='hot' 或 orderby='click' 表示按點(diǎn)擊數(shù)排列
orderby='sortrank' 或 orderby='pubdate' 按出版時(shí)間排列
orderby='near'
orderby='lastpost' 按最后評(píng)論時(shí)間
orderby='scores' 按得分排序
orderby='id' 按文章ID排序
orderby='rand' 隨機(jī)獲得指定條件的文檔列表
但織夢(mèng){dede:likearticle}卻沒(méi)有orderby這個(gè)功能。下面是修改方法
likearticle標(biāo)簽增加orderby排序功能
打開(kāi)/include/taglib/likearticle.lib.php,找到
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";//如果沒(méi)有特定設(shè)置排序則按照權(quán)重先排序 else $orderquery = " order by arc.sortrank $orderWay"; |
注意到排序是針對(duì)數(shù)字而言,因此只要這里就可以拓展成許多自定義排序,比如DedeCMS做商城時(shí)按照價(jià)格排序功能就可以這樣做。商城arclist、likearticle標(biāo)簽增加價(jià)格排序
在上面代碼最后一行前增加一行代碼
else if($orderby == 'trueprice') $ordersql = " order by addf.trueprice $orderWay";
arclist、likearticle標(biāo)簽增加主表自定義字段排序
實(shí)現(xiàn)自定義字段排序如{dede:arclist orderby='orderid' }
數(shù)據(jù)庫(kù)操作
用MYSQL的管理工具或者其他,修改dede_archives表結(jié)構(gòu),添加一列orderid字段
后臺(tái)文件操作
①修改article_add.php,改187行,字段和接收文本的值
//保存到主表 $query = "INSERT INTO `dede_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle, color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,orderid) VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money', '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate', '$adminid','$notpost','$description','$keywords','$filename','$adminid','$orderid');"; |
②修改article_edit.php,在191行
dutyadmin='$adminid'
下面增加一行
,orderid='$orderid'
③修改article_add.htm和article_edit.html,這個(gè)自行琢磨哦(懂點(diǎn)HTML知識(shí)的都會(huì)哦)
前臺(tái)文件操作
①修改include/arc.listview.class.php,在第551行至555行處添加如下代碼:
else if($orderby=="orderid") {
$ordersql = " order by arc.orderid $orderWay";
}
②修改594行代碼,修改如下(此步驟是參考他人的,可以省略,個(gè)人測(cè)試了,不起作用)
if(ereg('hot|click|lastpost|orderid ',$orderby))
③修改taglib里的arclist.lib.php,235行添加如下代碼:
else if($orderby == 'orderid') $ordersql = " order by arc.orderid $orderWay";
這樣就能實(shí)現(xiàn)自定義字段的操作了。HTML模板調(diào)用如下:
{dede:arclist orderby='orderid' orderway='desc'}
這里是HTML部分
{/dede:arclist}
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)的likearticle相關(guān)標(biāo)簽支持隨機(jī)排序orderby方法