【实测】discuz帖子列表页调用封面图片-Discuz教程下载

【实测】discuz帖子列表页调用封面图片

开通本站Svip会员,全站资源免费下
打开文件:
source/module/forum/forum_forumdisplay.php
找到如下代码
  1. if($thread['rushreply']) {
  2.         $rushtids[$thread['tid']] = $thread['tid'];
  3. }
复制代码
在这段代码下面添加如下代码:
  1. $threada= C::t('forum_attachment')->fetch_all_by_id('tid', $thread['tid'], 'aid');
  2. $threadaid = reset($threada);
  3. $threadpic = C::t('forum_attachment_n')->fetch_by_aid_uid($threadaid['tableid'], $threadaid['aid'], $thread['authorid']);
  4. $thread['pic'] = $threadpic['attachment'];
复制代码
这样就可以在列表页模板中使用
  1. $thread['pic']
复制代码
$thread['pic']所调用的是“附件”不分格式,也就是说,有可能调用到.rar/.zip之类的附件,并不是专调图片,算是个弊端。
默认调用第一张且只能调用一张图
我是这样调用的
  1. <img src="/data/attachment/forum/{$thread['pic']}"/>
复制代码
如果需要加上链接或判断的话,则这么写
  1. <!--{if $thread['pic']}-->
  2.                                                                                 <a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst"><img src="/data/attachment/forum/{$thread['pic']}"/></a>
  3.                                                                                 <!--{else}-->
  4.                                                                                 <a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else} onclick="atarget(this)"{/if} class="s xst"><img src="/favicon.ico"/></a>
  5.                                                                                 <!--{/if}-->
复制代码
意思为有封面则调用封面,无封面则调用根目录里的favicon.ico图标,可根据自身需求修改对应图片

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部