BoonKiong.com2026™

人气 13

Discuz! diy 随机调用帖子 [复制链接]

boonkiong 昨天 21:28

简单来说,就是每隔一段时间(自己设定的数据缓存时间),即使没有新帖子,这个diy模块所调用的帖子也会变。

方法:加个选项,然后查询数据的时候把这个选项作为一个条件,选它就按它来调用。

具体操作:

1、打开/source/class/block/forum/block_threadhot.php,查找:

  1. array('recommends', 'threadlist_orderby_recommends'),
复制代码


在下边添加:

  1. array('rands', '随机'),
复制代码


2、打开/source/class/block/forum/block_thread.php,查找:

  1. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
  2. $lastposter = !empty($parameter['lastposter']) ? $parameter['lastposter'] : '';
复制代码


修改为:

  1. $orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends','rands')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
  2. $lastposter = !empty($parameter['lastposter']) ? $parameter['lastposter'] : '';
复制代码


继续查找:

  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=='rands'){
  2. $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;");
  3. }else{
  4. $query = DB::query("SELECT DISTINCT t.*$sqlfield
  5. FROM `".DB::table('forum_thread')."` t
  6. $sqlfrom WHERE {$maxwhere}t.readperm='0'
  7. $sql
  8. AND t.displayorder>='0'
  9. ORDER BY t.$orderby DESC
  10. LIMIT $startrow,$items;"
  11. );
  12. }
复制代码


就是在数据查询的外层加上了判断,如果是随机排序,查询里排序条件就用ORDER BY rand(),否则按原本的排序条件。



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

您还未登录

随手拍~~:

置顶文章~~:

热度会员~~:

boonkiongadminJustinIroms

手机版|小黑屋|网站地图|文强阁

GMT+8, 2026-7-12 05:09 , Processed in 0.040137 second(s), 24 queries .

Powered by Discuz! X3.5  © 2001-2017 Discuz Team.