搜索

Discuz!教程 Discuz!教程之DIY主题模块增加主题随机排序功能

一定 2021-12-01 广东省
Discuz默认规则里面是没有随机排序的,本教程介绍如果添加随机排序:

修改文件
游客,如果您要查看本帖隐藏内容请回复


1、参考文件有三个修改点,请按照修改点修改。

2、如果您的网站是gbk的,修改前请务必将block_thread.php文件编码格式转成gbk的,否则前台会乱码。

修改点1

找到代码
[PHP] 纯文本查看 复制代码
'orderby' => array(
        'title' => 'threadlist_orderby',
        'type'=> 'mradio',
        'value' => array(
                array('lastpost', 'threadlist_orderby_lastpost'),
                array('dateline', 'threadlist_orderby_dateline'),
                array('replies', 'threadlist_orderby_replies'),
                array('views', 'threadlist_orderby_views'),
                array('heats', 'threadlist_orderby_heats'),
                array('recommends', 'threadlist_orderby_recommends'),
        ),
        'default' => 'lastpost'
),

修改为
[PHP] 纯文本查看 复制代码
'orderby' => array(
        'title' => 'threadlist_orderby',
        'type'=> 'mradio',
        'value' => array(
                array('lastpost', 'threadlist_orderby_lastpost'),
                array('dateline', 'threadlist_orderby_dateline'),
                array('replies', 'threadlist_orderby_replies'),
                array('views', 'threadlist_orderby_views'),
                array('heats', 'threadlist_orderby_heats'),
                array('recommends', 'threadlist_orderby_recommends'),
                array('rand', '随机排序'),
        ),
        'default' => 'lastpost'
),


修改点2

找到代码

[PHP] 纯文本查看 复制代码
$orderby        = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';


修改为
[SQL] 纯文本查看 复制代码
$orderby        = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends','rand')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';


修改点3
找到代码
[PHP] 纯文本查看 复制代码
$query = DB::query("SELECT DISTINCT t.*$sqlfield
        FROM `".DB::table('forum_thread')."` t
        $sqlfrom WHERE {$maxwhere}t.readperm='0'
        $sql
        AND t.displayorder>='0'
        ORDER BY t.$orderby DESC
        LIMIT $startrow,$items;"
        );


修改为

[PHP] 纯文本查看 复制代码
if($orderby=='rand'){
        $query = DB::query("SELECT DISTINCT t.*$sqlfield
                FROM `".DB::table('forum_thread')."` t
                $sqlfrom WHERE {$maxwhere}t.readperm='0'
                $sql
                AND t.displayorder>='0'
                ORDER BY rand()
                LIMIT $startrow,$items;"
                );
}else{
        $query = DB::query("SELECT DISTINCT t.*$sqlfield
                FROM `".DB::table('forum_thread')."` t
                $sqlfrom WHERE {$maxwhere}t.readperm='0'
                $sql
                AND t.displayorder>='0'
                ORDER BY t.$orderby DESC
                LIMIT $startrow,$items;"
                );                        
}




一定

一定,洪荒文学创始人。



上一篇:discuz的tag标签列表页排序问题:实现新帖在前下一篇:修复注册的时候无法获取邮箱地址的问题

使用道具 举报

查看本帖隐藏内容
回复
2021-12-01
一定 楼主 广东省
嘿嘿
回复
2022-06-06
官方QQ群
扫码下载APP
返回顶部