虚位以待(AD)
虚位以待(AD)
首页 > CMS教程 > Discuz! > discuz教程:帖子列表页获取封面图片

discuz教程:帖子列表页获取封面图片
类别:Discuz!   作者:码皇   来源:互联网   点击:

找到文件source module forum forum_forumdisplay php复制代码大于809行找到如下代码if($thread) { $rushtids] = $thread;}复制代码在这段代码下面添加如下代码: $threada= C::t( forum_attachment )-fetch_a ,魔客吧
找到文件

  1. source/module/forum/forum_forumdisplay.php
复制代码
大于809行找到如下代码

  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']
复制代码
来加载一张封面图片,但是需要注意这样是加载最后一张插入的图片!
如果要改为第一张图片还需要修改另外的一个文件

找到文件

  1. source/class/table/table_forum_announcement.php
复制代码
找到

  1. $orderby = 'ORDER BY '.DB::order($orderby, 'DESC');
复制代码
修改为:

  1. $orderby = 'ORDER BY '.DB::order($orderby, 'ASC');
复制代码

好了这样就可在列表页,加载发帖时上传的第一张图片,做为封面来调用了!
相关热词搜索: discuz教程:帖子列表页获取封面图片