dede織夢技巧:教你徹底解決dede按權重排序的問題

dede排序對網站來說一直存在問題,默認是按照最新發布時間排序。這樣排序有個問題,一旦更新之後即被視爲最新發布,於是原本做好的排序瞬間就亂了。

這種時候,按權重排序是個很好的選擇,但按權重排序到處存在BUG~。很多地方都缺少設置,要麼是設定後完全不起作用,在百度和論壇找了很多帖子,都沒能完全解決問題。在做第二個網站的時候,終於把BUG修訂完全了。

要解決權重排序的問題,主要集中在以下幾個文件上:

/include/arc.freelist.class.php   自由列表對應的文件

/dede/templets/freelist_edit.htm 新增自由列表對應的文件

/dede/templets/freelist_add.htm  修改自由列表對應的文件

/include/arc.listview.class.php   list列表對應的文件

/include/taglib/arclist.lib.php   arclist列表對應的文件

修改的內容很簡單,按照以下步驟即可修正:

1、打開/include/arc.freelist.class.php, 找到以下代碼:

else if($orderby=="rand")
{
$ordersql = "  ORDER BY rand()";
}

在代碼下方插入以下代碼後保存:

else if($orderby=="weight") 
{
$ordersql = " order by arc.weight asc";
}

2、打開/dede/templets/freelist_add.htm,找到以下代碼:

<td height="28" align="left">排列順序:
         <select name="orderby" id="orderby" style="width:120">

在代碼下方插入以下代碼,保存:

<option value="weight">權重值</option>

3、打開/dede/templets/freelist_edit.htm,找到以下代碼:

<?php
       echo "<option value=\"$orderby\" selected>{$sortarrs[$orderby]}</option>\r\n";
?>

在代碼下方插入以下代碼,保存:

<option value="weight">權重值</option>

4、打開/include/arc.listview.class.php,找到以下代碼:

else if($orderby=="lastpost") 
{
      $ordersql = "  ORDER BY arc.lastpost $orderWay";
 }

在代碼下方插入以下代碼:

else if($orderby=="weight") 
{
$ordersql = " order by arc.weight asc";
}

找到以下代碼:

if(preg_match('/hot|click|lastpost|/', $orderby))

替換爲以下代碼並保存:

if(preg_match('/hot|click|lastpost|weight/', $orderby))

5、打開/include/taglib/arclist.lib.php,找到以下說明文字:

//功能:增加按好評數和差評數調用

替換爲以下代碼並保存:

else if($orderby == 'weight') $ordersql = "  ORDER BY arc.weight asc";
//功能:增加按好評數和差評數調用

 

修改這5個文件,即能解決權重排序的問題(根據權重從小到大排列),並使得自由列表中,也可以採用權重排序的方式生成列表。

調用例子:

{dede:arclist flag='a' limit='0,1' typeid='10' isweight='y' orderby='weight'}
        <a href="/z/al/index_12_1.html" target="_blank">
        <img src="[field:picname/]" width="300" height="168" alt="[field:shorttitle/]" style="border:1px solid "></a>
{/dede:arclist}

獲取更多資料,進入QQ羣:543592003

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章