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('此处替换成您的网址/zb_users/theme/b2c/include/news01.html')}和{file_get_contents('此处替换成您的网址/zb_users/theme/b2c/include/news02.html')}