能調出論壇 html 格式的網頁,首頁調用就很簡單了。
具體方法:
新建一個文本文件,把以下代碼保存在文本文件中,然後把它重命名為 cron_makehtml_daily.php, 即 php 文件,然後通過 ftp 工具把
cron_makehtml_daily.php 上傳到論壇目錄下的/source/include/cron/目錄中。
- <?php
- /*
- 調用論壇的 10 個最新帖子,輸出為 html 格式,通過計劃任務更新,更新時間可以在計劃任務中設置
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- $newhtml = '';
- $query = DB::query("SELECT t.*, f.name FROM
eddsbbs_forum_thread t, eddsbbs_forum_forum f WHERE t.fid=f.fid and
f.fid IN('2','36','38','39','40','46') ORDER BY t.dateline DESC LIMIT 0,
10"); //這裏要修改你自己想要調用的版塊 ID - while($new = DB::fetch($query)) {
- $newsubject = cutstr($new['subject'],48);
- $newurl =
'http://www.ecostet.com/eddsbbs/thread-'.$new['tid'].'-1-1.html'; - $newhtml .= '<li><a target="_blank"
href="'.$newurl.'">'.$newsubject.'</a></li>'; - }
- $newhtml = convert_data($newhtml);
- writehtml('newhtml.htm', $newhtml);
- //寫入 html 文件
- function writehtml($file, $html) {
- global $timestamp;
- $yearmonth = gmdate('Ym', $timestamp + 8 * 3600);
- $logdir = DISCUZ_ROOT.'./data/cache/';
- $logfile = $logdir.$file;
- if($fp = @fopen($logfile, 'w')) {
- @flock($fp, 2);
- fwrite($fp, "$html");
- fclose($fp);
- }
- }
- function convert_data($data) {
- include_once
DISCUZ_ROOT.'./source/class/class_chinese.php'; - $c = new Chinese('gbk', 'utf8');
- $data = $c->Convert($data);
- return $data;
- }
- ?>
上
面是夫唯老師提供給我的代碼,因為我本身的服務器環境是 utf-8 的,所以我註釋了 2 段代碼,才顯示正常
第一段代碼,是編碼轉換
- //$newhtml =
convert_data($newhtml);
第二段代碼,編碼轉換的方法
- /* function
convert_data($data) { - include_once
DISCUZ_ROOT.'./source/class/class_chinese.php'; - $c = new Chinese('gbk', 'utf8');
- $data = $c->Convert($data);
- return $data;
- }*/
然
後登陸論壇後台管理中心,工具-> 計劃任務,增加一個新的計劃任務名 「輸出 html」,名字可以自己取,然後點擊這個任務的 「編輯」,在 「任務腳
本」 裏面輸入:cron_makehtml_daily.php,其他更新時間設置,自己選擇,也可以保持默認,點擊 「提交」 。
然後,通過這個地址 http://www.ecostet.com/eddsbbs/data/cache/newhtml.htm,可以獲得 html 格
式的論壇最新 10 個帖子,如果顯示亂碼,切換到 UTF-8 編碼下查看。
然後在首頁 index.php 中,添加一個方法:
- function
readBbsHtml() //output bbs latest topic - {
- $content =
file("http://www.ecostet.com/eddsbbs/data/cache/newhtml.htm"); - $content = implode("
",$content); - return $content;
- }
在
首頁需要調用的地方,調用 readBbsHtml() 方法即可。