我的知识记录

请问zblog(非js)调用discuz帖子的方法

步骤1:在zblog目录(以b2c主题为例)/zb_users/theme/b2c/include目录下,新建空文件news01.html和news02.html。

 

步骤2:复制以下代码保存为news.php,上传到discuz程序的sources/include/cron/目录下。

<?php if(!defined('IN_DISCUZ')) { exit('Access Denied'); }  //单独id(根据您的需求修改fid,末尾的数字5代表调用的条数) $query01 = DB::query("SELECT tid,subject,dateline FROM ".DB::table('forum_thread')." where fid=71 AND displayorder>=0 order by dateline desc limit 0,5"); while ($value = DB::fetch($query01)) { $txtstr01.= "<dd><span>[".date("m月d日",$value['dateline'])."]</span><a href='/bbs/forum.php?mod=viewthread&tid=".$value['tid']."&extra=page%3D1' target='_blank' title='".$value['subject']."'>".$value['subject']."</a></dd>\n"; } file_put_contents('../zb_users/theme/b2c/include/news01.html', $txtstr01);  //多个id(根据您的需求修改fid,末尾的数字5代表调用的条数) $query02 = DB::query("SELECT tid,subject,dateline FROM ".DB::table('forum_thread')." where fid in (51,52,55,66,68,69,72,73,74,75,76,77,78,79,80,81,82,83,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103) AND displayorder>=0 order by dateline desc limit 0,5"); while ($value = DB::fetch($query02)) { $txtstr02.= "<dd><span>[".date("m月d日",$value['dateline'])."]</span><a href='/bbs/forum.php?mod=viewthread&tid=".$value['tid']."&extra=page%3D1' target='_blank' title='".$value['subject']."'>".$value['subject']."</a></dd>\n"; } file_put_contents('../zb_users/theme/b2c/include/news02.html', $txtstr02);  ?>


步骤3:登录discuz后台管理—工具—计划任务,新建名为“zblog调用帖子”的任务,在“可用”栏中勾选并提交。

 

步骤4:根据您的需求来修改计划任务的时间,这里默认为每隔5分钟执行一次。

 

设置后就可以在zblog模板文件中进行调用了,调用代码为:{file_get_contents('https://域名/zb_users/theme/b2c/include/news01.html')}和{file_get_contents('https://域名/zb_users/theme/b2c/include/news02.html')}

标签:zblog开发教程-zblogphp-zblog插件开发-zblog插件-zblog开发文档-

更新时间:2025-04-11 00:00:56

上一篇:请问Z-BlogPHP 中“主题模板的编译文件不存在”错误的原因是什么?

下一篇:请问pbootcms网站是使用sqlite数据库好还是使用mysql数据库好