找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2205|回复: 0

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

[复制链接]
发表于 2017-11-14 13:03:10 | 显示全部楼层 |阅读模式 来自 河南省新乡市
20170614134539649.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',
复制代码
修改为
  1. $orderby    = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats',
复制代码
修改点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. }  
复制代码


发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

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

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-6-6 01:57 , Processed in 0.034002 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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