网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > WordPress
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 218.2.66.169
Old 2012-06-11, 09:36 PM
car car is offline
高级会员
 
Join Date: 2006-05-14
Posts: 534
car 正向着好的方向发展
Default WordPress调用Discuz内容

这个调用首要条件是Discuz是为二级目录,并且跟WordPress共用一个数据库。
前提:
主站:Wordpress程序,演示:你的域名
论坛:Discuz程序,演示:你的域名/bbs/
教程开始。。。。
第一步:创建makehtml_daily.inc.php文件:
在记事本中,复制下面的代码进去,并另存为 makehtml_daily.inc.php;也就是php文件。
然后把 makehtml_daily.inc.php 文件,通过FTP上传到论坛的 ./include/crons/ 目录中。

请把下面代码中的一些内容要修改一下:
$newurl = ‘你的域名/bbs/thread-’.$new['tid'].’-1-1.html’;把红色地址修改为你自己的域名。另外,请注意这里是静态化的URL,如果你的论坛没静态化,请换为动态的URL。
/*
调用论坛的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″);
//这里的f.fid in (’8′,’2′,’38′,’50′) 要改成自己想要调用的版块号,LIMIT 0, 10″),其中的10是调用帖子的数量。
while($new = $db->fetch_array($query)) {
$newsubject = cutstr($new['subject'],42);
$newurl = ‘http://www.xuyi.biz/bbs/thread-’.$new['tid'].’-1-1.html’;
$newhtml .= ‘
’.$newsubject.’

’;
}
//$newhtml = convert_data($newhtml);
//如果您的服务器本来就是uft8的,这行应该注释掉。

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);
}
}

//如果您的服务器本来就是uft8的,下面的函数也注释掉
/* function convert_data($data) {

include DISCUZ_ROOT.’include/chinese.class.php’;
$c = new Chinese(‘gbk’, ‘utf8′);
$data = $c->Convert($data);
return $data;
}
?> */

第二步:新增计划任务:
在论坛的后台,工具->计划任务—>增添一个任务,然后点击这个任务的“编辑”,在“任务脚本:”的输入框里输入:makehtml_daily.inc.php。其他更新时间设置,可以自己选择。
然后,通过这个地址:你的域名/bbs/forumdata/cache/newhtml.htm可以获得HTML格式的论坛帖子。(注:在这个地址中看到的是乱码也没有关系,请修改下浏览器,采用utf8查看。)

第三步:在主站调用论坛帖子:
登陆主站Wordpress后台,点外观》编辑》边栏模板 (sidebar.php),查找以下代码:




在这行代码的上面加入以下代码:



$url='http://www.xuyi.biz/bbs/forumdata/cache/newhtml.htm';
$fp = fopen($url, 'r');
while(!feof($fp)) {
$result .= fgets($fp, 1024);
}
echo "$result";
fclose($fp);
?>
点击更新文件,刷新首页,看看效果是不是可以了。

注:如不可以,请查看是否有全角符号,如有替换成半角即可,本站已禁止WP拷贝代码时会自动将半角转换为全角的问题,请自行尝试!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 03:39 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.