DeDeCMS自定义功能

DeDeCMS文档默认按最后时间排序的,如果某一文章需要置顶,那么只要重新编辑提交该文章就顶上去了,可是导致的问题也是很多,如果你希望你最近更新的文章在第十条插入的话,那么你需要把这十一条内容重新提交一次,按照顺序!

所以,这么复杂,这么不科学的方法显然不适合我们。

二次开发版

新建一个表,让这个表控制每个文章的数值,我们依靠这个数值来排列,类似添加文章里TAG旁的那个权重一样,我们也给他添加一个权重,只不过这个权重是用来控制文章的排序顺序。

OK,想法有了,那么就开始实现吧,百度了一圈,发现之前也有站长和我相同想法的,不过他们提供的方法是对照旧版DEDE而言,新版不适合他们的代码,不过依葫芦画瓢咱还是可以的。

废话不多说,教程开始

步骤比较多,但是都很简单,无脑操作的,有需要的朋友请认真一步步看下去。

数据库操作

1:首先得给数据库添加一个表,让它来记录这个权重。所以我们进入PHPMYADMIN,找到dede_archives选择结构一栏进入,然后添加表orderid

文件修改

1、打开 根目录/dede/article_add.php //修改代码文件

搜索找到

$query = "INSERT INTO `dede_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
    color,writer,source,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight)
    VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money',
    '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
    '$adminid','$voteid','$notpost','$description','$keywords','$filename','$adminid','$weight');";

修改为

$query = "INSERT INTO `dede_archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
    color,writer,source,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight,orderid)
    VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money',
    '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
    '$adminid','$voteid','$notpost','$description','$keywords','$filename','$adminid','$weight','$orderid');";

2、打开dede/article_edit.php     //修改代码文件
搜索weight='$weight'在它之后加逗号并回车换行加入以下代码orderid='$orderid'
3、打开dede/templets/article_add.htm    //修改模板文件
在适合位置添加以下代码,我是在内容摘要之后添加的。

<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:3px;">
       <tbody>
  <tr> 
        <td width="90" class="bline" height="24">&nbsp;排序权重:</td>
        <td class="bline"><input type='text' name='orderid' value='0' style='100px;' />(请填写数字,越大越靠前)</td>
  </tr>
  </tbody>
  </table>

4、打开dede/include/arc.listview.class.php //修改模版文件
搜索 

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

修改为

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

5、打开dede/templets/article_edit.html    //修改模板文件
在适合位置添加以下代码,我是在文章副栏目之后添加的

<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:3px;">
       <tbody>
    <tr>
    <td width="90" class="bline" height="24"> 排序权重:</td>
    <td  class="bline"><input type='text' name='orderid' value='<?php echo $arcRow["orderid"]?>' style='100px;' />(请填写数字,越大越靠前)</td>
    <td></td>
    </tr>
    </tbody></table>

6、打开include/arc.listview.class.php     //修改代码文件
搜索

else if($orderby=="hot" || $orderby=="click") {
            $ordersql = " ORDER BY arc.click $orderWay";
        }
在其后添加
else if($orderby=="orderid") {
            $ordersql = " order by arc.orderid $orderWay"; //orderid为dede_archives表里面自己添加的字段
            }

7、打开include/taglib/arclist.lib.php     //修改代码文件
搜索

else if($orderby == 'id') $ordersql = “ORDER BY arc.id $orderWay”;

在它之后回车增加一行,加入以下代码

else if($orderby == ‘orderid’) $ordersql = “order by arc.orderid $orderWay,arc.id $orderWay”;
8、最后在HTML模板调用如下:
{dede:arclist typeid=’1′ row=’10′ titlelen=’60′  orderby=′orderid′}
 
《你的模版文件代码》
 
{/dede:arclist}

第二部分: 修改排序

1.

image

2.

image

 

如果想一次增加加10   $maxOrderid[‘id’] += 10;    image

 

3.

image

4.

image

第3部分 解决自定义排序上一篇下一篇链接不对应问题

打开文件   includearc.archives.class.php 文件

修改808行的代码如下

$preR =  $this->dsql->GetOne("Select id From `#@__archives` where orderid<{$this->Fields['orderid']} And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by orderid desc");
$nextR = $this->dsql->GetOne("Select id From `#@__archives` where orderid>{$this->Fields['orderid']} And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by orderid asc");

这样就上一篇/下一篇链接和自定义排序的链接相符了.

但是问题来了, 旧文档的上一篇,下一篇链接失效, 解决方法是加上一个判断语句

if($this->Fields['orderid'] >=1){                
$preR =  $this->dsql->GetOne("Select id From `#@__archives` where orderid<{$this->Fields['orderid']} And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by orderid desc");
$nextR = $this->dsql->GetOne("Select id From `#@__archives` where orderid>{$this->Fields['orderid']} And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by orderid asc");                                                        
            }else{
$preR =  $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
$nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");                            
            }
原文地址:https://www.cnblogs.com/Bigbirdblog/p/4988829.html