|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如图,添加后的效果,Discuz默认规则里面是没有随机排序的,本教程介绍如果添加随机排序: 修改文件 \source\class\block\forum\block_thread.PHP 1、参考文件有三个修改点,请按照修改点修改。 2、如果您的网站是gbk的,修改前请务必将block_thread.php文件编码格式转成gbk的,否则前台会乱码。 修改点1 找到代码
- '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'
- ),
复制代码修改为
- '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 找到代码 - $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
复制代码修改为 - $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends','rand')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
复制代码修改点3
找到代码
- $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;"
- );
复制代码修改为 - 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;"
- );
- }
复制代码
|
|