硬汉工作室

搜索
热搜: 活动 交友 discuz

[开发技术] Discuz DIY缩略图获取内容里的第一张

[复制链接]
发表于 2020-7-9 15:51:33 | 显示全部楼层 |阅读模式
默认情况下,diy获取的贴子的缩略图是从forum_threadimage表里获取的,但是有时候我们希望获取贴子内容里的第一张,那么可以修改source/class/block/forum/forum_thread.php,找到getdata方法,修改如下:
while($data = DB::fetch($query)) { // 从getdata方法里找到这行,添加下面的代码:
                       
        $msg = DB::result_first('select message from %t where tid = %d and first = 1', array('forum_post', $data['tid']));
        preg_match_all("/\[attach\](\d+)\[\/attach\]/i", $msg, $matches);
        $firstaid = intval($matches[1][0]);
        if($firstaid) {
                $imgrs = C::t('forum_attachment_n')->fetch('tid:'.$data['tid'], $firstaid);
                 $data['attachmenturl'] = $imgrs['attachment'];
        }

        // 其他代码
}


其实原理就是根据tid获取楼主内容的附件id,然后获取第一个附件id来获取图片。

有关PHP系统、Discuz或网站等各种问题,可以联系QQ1069971363寻求付费支持
Discuz插件商店:http://addon.dismall.com/?@56030.developer
回复

使用道具 举报

QQ|Archiver|手机版|小黑屋|硬汉工作室 ( 冀ICP备13021567号-9 )

GMT+8, 2024-5-15 12:25 , Processed in 0.053448 second(s), 23 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表