簡(jiǎn)單的說(shuō),就是每隔一段時(shí)間(自己設(shè)定的數(shù)據(jù)緩存時(shí)間),即使沒(méi)有新帖子,這個(gè)diy模塊所調(diào)用的帖子也會(huì)變。
方式:加個(gè)選項(xiàng),然后查詢數(shù)據(jù)的時(shí)候把這個(gè)選項(xiàng)作為一個(gè)條件,選它就按它來(lái)調(diào)用。

具體操作:
1.打開(kāi)/source/class/block/forum/block_threadhot.php,找到
array('recommends', 'threadlist_orderby_recommends'),
之下增加
array('rands', '隨機(jī)'),
2.打開(kāi)/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'] : '';
改為
$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;"
);
}
就是在數(shù)據(jù)查詢的外層加上了判斷,如果是隨機(jī)排序,查詢里排序條件就用ORDER BY rand(),否則按原本的排序條件。






