请选择 进入手机版 | 继续访问电脑版

Discuz!大师网

搜索
查看: 1294|回复: 0

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

[复制链接]
发表于 2017-7-18 09:15:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Center.jpg
如图,添加后的效果,Discuz默认规则里面是没有随机排序的,本教程介绍如果添加随机排序:
修改文件 \source\class\block\forum\block_thread.PHP
1、参考文件有三个修改点,请按照修改点修改。
2、如果您的网站是gbk的,修改前请务必将block_thread.php文件编码格式转成gbk的,否则前台会乱码。
修改点1
找到代码

  1. 'orderby' => array(
  2.         'title' => 'threadlist_orderby',
  3.         'type'=> 'mradio',
  4.         'value' => array(
  5.                 array('lastpost', 'threadlist_orderby_lastpost'),
  6.                 array('dateline', 'threadlist_orderby_dateline'),
  7.                 array('replies', 'threadlist_orderby_replies'),
  8.                 array('views', 'threadlist_orderby_views'),
  9.                 array('heats', 'threadlist_orderby_heats'),
  10.                 array('recommends', 'threadlist_orderby_recommends'),
  11.         ),
  12.         'default' => 'lastpost'
  13. ),
复制代码
修改为

  1. 'orderby' => array(
  2.         'title' => 'threadlist_orderby',
  3.         'type'=> 'mradio',
  4.         'value' => array(
  5.                 array('lastpost', 'threadlist_orderby_lastpost'),
  6.                 array('dateline', 'threadlist_orderby_dateline'),
  7.                 array('replies', 'threadlist_orderby_replies'),
  8.                 array('views', 'threadlist_orderby_views'),
  9.                 array('heats', 'threadlist_orderby_heats'),
  10.                 array('recommends', 'threadlist_orderby_recommends'),
  11.                 array('rand', '随机排序'),
  12.         ),
  13.         'default' => 'lastpost'
  14. ),
复制代码
修改点2
找到代码
  1. $orderby    = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';  
复制代码
修改为
  1. $orderby    = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends','rand')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';  
复制代码
修改点3

找到代码

  1. $query = DB::query("SELECT DISTINCT t.*$sqlfield
  2.         FROM `".DB::table('forum_thread')."` t
  3.         $sqlfrom WHERE {$maxwhere}t.readperm='0'
  4.         $sql
  5.         AND t.displayorder>='0'
  6.         ORDER BY t.$orderby DESC
  7.         LIMIT $startrow,$items;"
  8.         );
复制代码
修改为
  1. if($orderby=='rand'){
  2.         $query = DB::query("SELECT DISTINCT t.*$sqlfield
  3.                 FROM `".DB::table('forum_thread')."` t
  4.                 $sqlfrom WHERE {$maxwhere}t.readperm='0'
  5.                 $sql
  6.                 AND t.displayorder>='0'
  7.                 ORDER BY rand()
  8.                 LIMIT $startrow,$items;"
  9.                 );
  10. }else{
  11.         $query = DB::query("SELECT DISTINCT t.*$sqlfield
  12.                 FROM `".DB::table('forum_thread')."` t
  13.                 $sqlfrom WHERE {$maxwhere}t.readperm='0'
  14.                 $sql
  15.                 AND t.displayorder>='0'
  16.                 ORDER BY t.$orderby DESC
  17.                 LIMIT $startrow,$items;"
  18.                 );                       
  19. }
复制代码


回复 马甲回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|网站地图|小黑屋|展会网|Discuz站长论坛 |天天打卡

GMT+8, 2024-4-16 22:34 , Processed in 0.050443 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表