吾知网

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 5069|回复: 0
打印 上一主题 下一主题

DedeCMS非JS方法调用Discuz论坛数据(含非同一数据库下)

[复制链接]
跳转到指定楼层
楼主
发表于 2015-10-30 18:19:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近在整合dedecms5.6和discuz! x1.5,希望能通过dede首页来调用discuz的相关帖子数据,由于discuzx 后台-门户-模块管理-数据调用 只能以JS方式远程调用论坛的数据,这里说说用DEDE的标记语言直接从数据库调用,这样的优点就是方便蜘蛛的抓取,但同时也会加重服务器的负担。
一、DEDECMS官方的调用动态地址代码:

论坛新帖子:
<br/>
{dede:loop table="pre_forum_thread " sort="tid" row="10"}
    <a href="http://bbs.xx.com/viewthread.php?tid=[field:tid /]">
       [field:subject function="cn_substr('@me',30)" /]([field:lastpost function="date('m-d H:M','@me')" /])
   </a>
<br/>
{/dede:loop}

其中的 http://bbs.xx.com/ 是论坛的地址;pre_forum_thread 数据库的表名;('@me',30)调用标题的字符数30,相当于15个汉字;([field:lastpost function="date('m-d H:M','@me')" /])  标题后调用发帖的时间,可按需要调用。
二、调用Discuz论坛伪静态地址代码,dedecms数据库和discuzx数据库不在同一库内。

{dede:loop table="discuzbbs.pre_forum_thread " sort="tid" row="10"}
    <a href="http://bbs.xx.com/thread-[field:tid /]-1-1.html" target="_blank">
        [field:subject function="cn_substr('@me',30)" /]
    </a>
{/dede:loop}

说明:discuzbbs.pre_forum_thread,其中红色的“discuzbbs”是discuz论坛的数据库名,pre_forum_thread是帖子表名,pre_替换为你的具体的表前缀。由此,也能看出DedeCMS的数据库和discuz的数据库不在同一个库内。
注:非同一库内的数据调用格式:discuz论坛数据库名.     ps.记得后面的点。
蓝色字体就是你的论坛地址   过这这能调用第一页的内容 thread-[field:tid /]-1-*.html *代表页数
三、DEDECMS调用指定分类文章

demo1:
{dede:loop table="discuzbbs.pre_forum_thread " if="fid=6 and displayorder!=-1" sort="tid" row="10" }
    <a href="http://bbs.xx.com/thread-[field:tid /]-1-1.html" target="_blank">[field:subject function="cn_substr('@me',28)"/]</a>
    [field:author /] [field:dateline function='GetDateMk(@me)'/]
{/dede:loop}

demo2:
{dede:loop table="discuzbbs.pre_forum_thread " if="fid=1||fid=2 and displayorder!=-1" sort="tid" row="6"}
    <a href="http://bbs.xx.com/viewthread.php?tid=[field:tid /]" target="_blank">
        [field:subject function="cn_substr('@me',50)" /]
    </a>
{/dede:loop}

说明:[field:author /] [field:dateline function='GetDateMk(@me)'/] 调用作者和文章时间
fid=6 是discuz栏目的ID


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|吾知网 ( 粤ICP备13013563号-1 )

GMT+8, 2024-4-27 01:50 , Processed in 1.062500 second(s), 10 queries , Memcache On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表