默认情况下,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寻求付费支持
|