www.seowhy.com 基础指南的右侧有10个帖子是从SEOWHY论坛调出,并通过以下代码,实现调出的是hmtl格式的内容,起到为基础指南每个文章实时更新的作用。
应大家要求,今天分享这个具体操作办法。
建站初期,可以不用考虑这个细节。
具体实现办法:
把以下代码,放入记事本文件,然后,把记事本的名称修改为 makehtml_daily.inc.php 即php文件。
然后把 makehtml_daily.inc.php 文件,通过ftp上传到./include/crons/ 目录中。
本代码里的一些内容要进行修改:
$newurl = 'http://www.seowhy.com/bbs/thread-'.$new['tid'].'-1-1.html'; 地址,修改为你自己的域名。
- <?php
- /*
- 调用论坛的10个最新帖子,输出为html格式,通过计划任务更新,更新时间可以在计划任务中设置
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- $newhtml = '';
- $query = $db->query("SELECT t.*, f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE t.fid=f.fid and f.fid IN('8','2','38','50') ORDER BY t.dateline DESC LIMIT 0, 10");
- while($new = $db->fetch_array($query)) {
- $newsubject = cutstr($new['subject'],42);
- $newurl = 'http://www.seowhy.com/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, $_DCACHE;
- $yearmonth = gmdate('Ym', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
- $logdir = DISCUZ_ROOT.'./forumdata/cache/';
- $logfile = $logdir.$file;
- if($fp = @fopen($logfile, 'w')) {
- @flock($fp, 2);
- fwrite($fp, "$html");
- fclose($fp);
- }
- }
- function convert_data($data) {
- include DISCUZ_ROOT.'include/chinese.class.php';
- $c = new Chinese('gbk', 'utf8');
- $data = $c->Convert($data);
- return $data;
- }
- ?>
评论0