找回密码
 立即注册
搜索

途迹耕耘

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

GMT+8, 2025-12-22 05:41 , Processed in 0.228304 second(s), 14 queries .

[DZ教程] discuz 帖子列表页调用封面图片

[复制链接]
bdk 发表于 2020-5-2 12:18:11 | 显示全部楼层 |阅读模式
打开文件:
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']
复制代码
20160130更新:
$thread['pic']所调用的是“附件”不分格式,也就是说,有可能调用到.rar/.zip之类的附件,并不是专调图片,算是个弊端。
我的模板里是这么调用的:
  1. <img src="http://file.cmsbj.cn/cmsbj_file/forum/$thread['attachments']['used']['0']['attachment']" alt="$thread[subject]"/>
复制代码
前面的网址是我的远程附件服务器地址,须改成自己的路径。这个是可以区分开附件类型,只调用图片。
网上说的默认是调用的最后一张图,但我测试的效果是就是默认调用第一张。
OK。