簡單的說,就是每隔一段時間(自己設定的數據緩存時間),即使沒有新帖子,這個diy模塊所調用的帖子也會變。
方式:加個選項,然后查詢數據的時候把這個選項作為一個條件,選它就按它來調用。
具體操作:
1.打開/source/class/block/forum/block_threadhot.php,找到
array('recommends', 'threadlist_orderby_recommends'),
之下增加
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'] : '';
改為
$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(),否則按原本的排序條件。