如何从论坛调出html格式的帖子

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';   地址,修改为你自己的域名。

  1. <?php
  2. /*
  3. 调用论坛的10个最新帖子,输出为html格式,通过计划任务更新,更新时间可以在计划任务中设置
  4. */
  5. if(!defined('IN_DISCUZ')) {
  6.         exit('Access Denied');
  7. }
  8. $newhtml = '';
  9. $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");
  10. while($new = $db->fetch_array($query)) {
  11.         $newsubject = cutstr($new['subject'],42);
  12.         $newurl = 'http://www.seowhy.com/bbs/thread-'.$new['tid'].'-1-1.html';
  13.         $newhtml .= '<li><a target="_blank" href="'.$newurl.'">'.$newsubject.'</a></li>';
  14. }
  15. $newhtml = convert_data($newhtml);
  16.  
  17. writehtml('newhtml.htm', $newhtml);
  18. //写入html文件
  19. function writehtml($file, $html) {
  20.         global $timestamp, $_DCACHE;
  21.         $yearmonth = gmdate('Ym', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600);
  22.         $logdir = DISCUZ_ROOT.'./forumdata/cache/';
  23.         $logfile = $logdir.$file;
  24.         if($fp = @fopen($logfile, 'w')) {
  25.                 @flock($fp, 2);
  26.                 fwrite($fp, "$html");
  27.                 fclose($fp);
  28.         }
  29. }
  30. function convert_data($data) {
  31.  
  32.         include DISCUZ_ROOT.'include/chinese.class.php';
  33.         $c = new Chinese('gbk', 'utf8');
  34.         
  35.         $data = $c->Convert($data);
  36.         return $data;
  37. }
  38. ?>
本文链接:https://www.dnwfb.com/494.html,转载请注明出处。
0

评论0

没有账号? 注册  忘记密码?