Discuz DIY 加入随机调用帖子的方法!


具体操作:
1.打开/source/class/block/forum/block_threadhot.php,找到

  1. array('recommends', 'threadlist_orderby_recommends'),

    之下增加

  2. array('rands', '随机'),

2.打开/source/class/block/forum/block_thread.php,找到

$orderby = isset($parameter['orderby']) ? (in_array($parameter['orderby'],array('lastpost','dateline','replies','views','heats','recommends')) ? $parameter['orderby'] : 'lastpost') : 'lastpost';
$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';
    $lastposter = !empty($parameter['lastposter']) ? $parameter['lastposter'] : '';

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=='rands'){
$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;"
);
}

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

网页代码 2022-01-17 21:35:27 通过 网页 浏览(143)

共有0条评论!

发表评论

更换一道题!