帖子列表页获取封面图片_discuz二次开发教程

时间:2018-12-21 14:35作者:网友投稿
找到文件
  1.  
  2. source/module/forum/forum_forumdisplay.php
  3.  

大于809行找到如下代码
  1.  
  2. if($thread['rushreply']) {
  3.         $rushtids[$thread['tid']] = $thread['tid'];
  4. }
  5.  

在这段代码下面添加如下代码:
  1.  
  2.         $threada= C::t('forum_attachment')->fetch_all_by_id('tid', $thread['tid'], 'aid');
  3.         $threadaid = reset($threada);
  4.         $threadpic = C::t('forum_attachment_n')->fetch_by_aid_uid($threadaid['tableid'], $threadaid['aid'], $thread['authorid']);
  5.         $thread['pic'] = $threadpic['attachment'];
  6.  


这样就可以在列表页模板中使用
  1. $thread['pic']

来加载一张封面图片,但是需要注意这样是加载最后一张插入的图片!
如果要改为第一张图片还需要修改另外的一个文件

找到文件
  1.  
  2. source/class/table/table_forum_announcement.php
  3.  

找到
  1.  
  2. $orderby = 'ORDER BY '.DB::order($orderby, 'DESC');
  3.  

修改为:
  1.  
  2. $orderby = 'ORDER BY '.DB::order($orderby, 'ASC');
  3.  



好了这样就可在列表页,加载发帖时上传的第一张图片,做为封面来调用了!

免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。