bucuo123 发表于 2019-4-5 14:47:00

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

帖子列表页获取封面图片_discuz二次开发教程
            
            找到文件
       
               
                       
                               
                       
                                source/module/forum/forum_forumdisplay.php
                       
                               
                [/ol,
       
大于809行找到如下代码
       
               
                       
                               
                       
                                if($thread['rushreply',) {
                       
                                        $rushtids[$thread['tid',, = $thread['tid',;
                       
                                }
                       
                               
                [/ol,
       
在这段代码下面添加如下代码:
       
               
                       
                               
                       
                                        $threada= C::t('forum_attachment')->fetch_all_by_id('tid', $thread['tid',, 'aid');
                       
                                        $threadaid = reset($threada);
                       
                                        $threadpic = C::t('forum_attachment_n')->fetch_by_aid_uid($threadaid['tableid',, $threadaid['aid',, $thread['authorid',);
                       
                                        $thread['pic', = $threadpic['attachment',;
                       
                               
                [/ol,
       
这样就可以在列表页模板中使用
       
               
                       
                                $thread['pic',
                [/ol,
       
来加载一张封面图片,但是需要注意这样是加载最后一张插入的图片!
如果要改为第一张图片还需要修改另外的一个文件
找到文件
       
               
                       
                               
                       
                                source/class/table/table_forum_announcement.php
                       
                               
                [/ol,
       
找到
       
               
                       
                               
                       
                                $orderby = 'ORDER BY '.DB::order($orderby, 'DESC');
                       
                               
                [/ol,
       
修改为:
       
               
                       
                               
                       
                                $orderby = 'ORDER BY '.DB::order($orderby, 'ASC');
                       
                               
                [/ol,
       
好了这样就可在列表页,加载发帖时上传的第一张图片,做为封面来调用了!
页: [1]
查看完整版本: 帖子列表页获取封面图片_discuz二次开发教程