dedecms,phpcmsv9调用DiscuzX2.5最新帖子和图片的方法

今天在整合dedecms和Discuz!的时候发现原来的调用不能用了,百度一下发现,自从Discuz!从7.0到Discuz!X1.5后,原有的表结构发生了变化,不仅如此,pre_forum_attachment表更是成了10个(pre_forum_attachment_0到pre_forum_attachment_9),又来的dede:loop和dede:sql调用方法显然是不能用了,但是如何才能完美的调用论坛里面的图片帖子呢?

研究了一下午,终于找到了方法,Discuz!在把pre_forum_attachment表编程10个后,多了一个表,即:pre_forum_threadimage,这个表是专门用来存放一个主题中的楼主贴图片附件中,宽度最大的一张图片,这个图片是用来论坛后台添加外部链接是选择只读取有图片的帖子时所用。所以这个方便多了,感觉有点像dedecms里面的flag='p'。

好了,废话一大堆,直接介绍方法:

  1. {dede:sql sql="SELECT`pre_forum_threadimage`.`tid`,`pre_forum_threadimage`.`attachment`,`pre_forum_thread`.`subject` FROM `pre_forum_threadimage` LEFT JOIN `pre_forum_thread`ON`pre_forum_thread`.`tid`=`pre_forum_threadimage`.`tid` order by tid desc LIMIT 0,2"}{/dede:sql}

其中链接为:你的论坛地址:您的论坛网址/forum.php?mod=redirect&tid=[field:tid /]&goto=lastpost#lastpost

如果是静态化,那么就是这样的:您的论坛网址/thread-[field:tid /]-1-1.html

标题:[field:subject/]                        图片:/data/attachment/forum/[field:attachment/]

我们还可以判断 按栏目调取  入下红色

 最终是这样的:

  1. {dede:sql sql="SELECT`pre_forum_threadimage`.`tid`,`pre_forum_threadimage`.`attachment`,`pre_forum_thread`.`subject` FROM `pre_forum_threadimage` LEFT JOIN `pre_forum_thread`ON`pre_forum_thread`.`tid`=`pre_forum_threadimage`.`tid`where  fid=2 order by tid desc LIMIT 0,6"}
  2. <dl>
  3. <dt><a href="论坛网址/thread-[field:tid /]-1-1.html"{target}><img src="论坛网址/data/attachment/forum/[field:attachment/]" alt="[field:subject/]" /></a></dt>
  4. <dd><a href="论坛网址/thread-[field:tid /]-1-1.html" title="[field:subject/]" target="_blank">[field:subject/]</a></dd>
  5. </dl>
  6. {/dede:sql}

下面介绍如何调用帖子,调用帖子就比较简单了,直接上代码吧:

  1. {dede:sql sql="select subject,tid from pre_forum_thread order by tid desc limit 0,6"}
  2. <li><a href="论坛网址/thread-[field:tid /]-1-1.html" title="[field:subject /]" target="_blank">[field:subject /]</a></li>
  3. {/dede:sql}

下面介绍phpcmsv9整合后的调取方法如下:

{pc:get sql="SELECT `boao_forum_threadimage`.`tid`,`boao_forum_threadimage`.`attachment`,`boao_forum_thread`.`subject` FROM `boao_forum_threadimage` LEFT JOIN `boao_forum_thread`ON`boao_forum_thread`.`tid`=`boao_forum_threadimage`.`tid` where fid=2 order by tid desc" num="4" cache="" return="data"}
{loop $data $key $val}

<li>
<a href="/bbs/forum.php?mod=viewthread&tid={$val[tid]}"><img src='/bbs/data/attachment/forum/{$val[attachment]}' title="{$val[subject]}" width="227" height="135"></a>
<div class='bottom_imgs'><h6>{str_cut($val[subject],58,'')}</h6><a href="/bbs/forum.php?mod=viewthread&tid={$val[tid]}"></a></div>
</li>
{/loop}
{/pc}

转载于:https://www.cnblogs.com/yuesha/articles/5148266.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值