Discuz如何让帖子列表的标题显示帖子附件中的图片

Discuz的代码还是比较容易看懂的。关键是要找到需要改的地方。
第1步:
forumdisplay.php,用来准备要显示的帖子列表,然后用forumdisplay.htm作为显示模板。
找到forumdisplay.php中的:

$query = $sdb->query("SELECT t.* FROM {$tablepre}threads t
        WHERE t.fid='$fid' $filteradd AND $displayorderadd
        ORDER BY t.displayorder DESC, t.$orderby $ascdesc
        LIMIT ".($filterbool ? $start_limit : $start_limit - $stickycount).", $tpp");

替换为:

$query = $sdb->query("SELECT t.*,min(att.attachment) as attm FROM {$tablepre}threads t
        LEFT JOIN {$tablepre}posts p ON p.tid=t.tid
        LEFT JOIN {$tablepre}attachments att ON att.tid=t.tid
        WHERE t.fid='$fid' $filteradd AND $displayorderadd
        GROUP BY t.tid
        ORDER BY t.displayorder DESC, t.$orderby $ascdesc
        LIMIT ".($filterbool ? $start_limit : $start_limit - $stickycount).", $tpp");

意思很简单,把附件表中对应第一个附件选出来。这里有一点要注意,需要考虑附件类型,加一个图片类型的where条件即可。

第二步:
修改forumdisplay.htm
把第237行的:

<span id="thread_$thread[tid]"><a href="viewthread.php?tid=$thread[tid]&extra=$extra"$thread[highlight]>$thread[subject]</a></span>

替换为:

<span id="thread_$thread[tid]"><a href="viewthread.php?tid=$thread[tid]&extra=$extra"$thread[highlight]><image width="100px" height="100px" src="attachments/$thread[attm]"/>$thread[subject]</a></span>

加个图片到链接里。

完成。

相关文章

仅有 1 条评论

  1. Notice: Undefined offset: 1 in /home2/yaogeme/public_html/var/Typecho/Common.php on line 846
    momotuu

    测试过了,可以用哦~O(∩_∩)O谢谢了。就是图片缩略的变形了.

    momotuu 回复
发表新评论