大家都知道seowhy基礎指南右上角的10個最新帖子是從seowhy論壇調出來的,很多朋友都想要在自己網站的首頁調用二級目錄論壇的最新帖子,只要能調出論壇html格式的網頁,首頁調用就很簡單了。
具體方法:
新建一個文本文件,把以下代碼保存在文本文件中,然后把它重命名為cron_makehtml_daily.php,即php文件,然后通過ftp工具把cron_makehtml_daily.php上傳到論壇目錄下的/source/include/cron/目錄中.
- <?php
- if(!defined(‘IN_DISCUZ’)) {
- exit(‘Access Denied’);
- }
- $newhtml = ”;
- $query = DB::query(“SELECT t.*, f.name FROM bbs_forum_thread t, bbs_forum_forum f WHERE t.fid=f.fid and f.fid IN(’2′,’36′,’37′,’39′,’40′,’42′) ORDER BY t.dateline DESC LIMIT 0, 10″); //這里要修改你自己想要調用的版塊ID
- while($new = DB::fetch($query)) {
- $newsubject = cutstr($new['subject'],48);
- $newurl = ‘http://www.100de.com.cn/bbs/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(‘utf8′,’gbk’);
- $data = $c->Convert($data);
- return $data;
- }
- ?>
上面是SEOWHY提供給我的代碼,因為我本身的服務器環境是utf-8的,所以我注釋了2段代碼,才顯示正常
第一段代碼,是編碼轉換
//$newhtml = convert_data($newhtml);
第二段代碼,編碼轉換的方法
然后登陸論壇后臺管理中心,工具->計劃任務,增加一個新的計劃任務名“輸出html”,名字可以自己取,然后點擊這個任務的“編輯”,在“任務腳本”里面輸入:cron_makehtml_daily.php,其他更新時間設置,自己選擇,也可以保持默認,點擊“提交”。
然后,通過這個地址=http://你的網址/bbs/data/cache/newhtml.htm,可以獲得html格式的論壇最新10個帖子,如果顯示亂碼,切換到UTF-8編碼下查看。
然后在首頁index.php中,添加一個方法:
- function readBbsHtml() //output bbs latest topic
- {
- $content = file(“http://你的網址/bbs/data/cache/newhtml.htm“);
- $content = implode(“/n”,$content);
- return $content;
- }
新聞熱點
疑難解答