吾爱汇站网官方联系方式

工作时间: 周一到周五早上09:00-11:00, 下午03:00-05:00, 晚上20:30-22:30(周六、日休息)
QQ: 211985957  168528823  97147700  53150916 汇聚、帮助、交流   E-Mail: postmaster@5ihz.cn
用户交流QQ群
1群21532443 2群413446685 ←提醒:请勿重复加群,谢谢!(本站提供低价收费技术服务,详情联系在线客服)

[Discuz教程] discuz帖子列表页如果调用帖子图片附件缩略图

[复制链接]
查看1318 | 回复0 | 2018-11-19 22:08:59 | 显示全部楼层 |阅读模式
有好多站长在问如何让帖子列表显示帖内的附件图,调用数量可以随意设置,这里贴出方法

121617ih22zhahhbriuchp.jpg

需要修改的文件,template/default/forum/forumdisplay_list.htm(这里以默认模板为例子,其他模板可以自行参考)
找到这段代码:
[代码]php代码:
1
<!--{loop $_G['forum_threadlist'] $key $thread}-->




在下面增加这端代码:
[代码]php代码:
01
<!--{eval $tbid = DB::result(DB::query("SELECT tableid FROM ".DB::table('forum_attachment')." WHERE `tid`= '$thread[tid]'"));}-->

02
<!--{if $tbid}-->

03
<!--{eval $picount = DB::fetch_all("SELECT aid FROM ".DB::table('forum_attachment_'.$tbid.'')." WHERE `tid`= '$thread[tid]' AND `isimage`=1;");}-->

04
<!--{eval $picnum = count($picount);}-->

05
<!--{if $picnum < 3}-->

06
<!--{eval $litpicnum = '1';}-->

07
<!--{elseif $picnum > 2 && $picnum < 6}-->

08
<!--{eval $litpicnum = '3';}-->

09
<!--{elseif $picnum > 5}-->

10
<!--{eval $litpicnum = '6';}-->

11
<!--{/if}-->

12
<!--{eval $covers = DB::fetch_all("SELECT attachment,aid,description FROM ".DB::table('forum_attachment_'.$tbid.'')." WHERE `tid`= '$thread[tid]' AND `isimage`=1 LIMIT 0,$litpicnum;");}-->

13
<!--{/if}-->




然后再查找到这段代码:
[代码]php代码:
1
<!-- end of table "forum_G[fid]" branch 1/3 -->




其上最近的</tr>之后增加
[代码]php代码:
01
<!--{if $tbid}-->

02
<tr>

03
<td></td>

04
<td></td>

05
<td colspan="4">

06
<!--{loop $covers $thecover}-->

07
<!--{if $litpicnum == 1}-->

08
<a href="forum.php?mod=viewthread&tid=$thread[tid]" class="z pipe" title="$thecover[aid]"><img src="data/attachment/forum/$thecover['attachment']" width="100" height="100"/></a>

09
<font class="z">This is what it is like to be with Trump.</font>

10
<!--{else}-->

11
<a href="forum.php?mod=viewthread&tid=$thread[tid]" class="z pipe" title="$thecover[aid]"><img src="data/attachment/forum/$thecover['attachment']" width="100" height="100"/></a>

12
<!--{/if}-->

13
<!--{/loop}-->

14
</td>

15
</tr>

16
<!--{/if}-->




再查找:
[代码]php代码:
1
<!--{if !$thread['forumstick'] && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->

2
<!--{if $thread['related_group'] == 0 && $thread['closed'] > 1}-->

3
<!--{eval $thread[tid]=$thread[closed];}-->

4
<!--{/if}-->

5
<!--{if $groupnames[$thread[tid]]}-->

6
<span class="fromg xg1"> [{lang from}: <a href="forum.php?mod=group&fid={$groupnames[$thread[tid]][fid]}"target="_blank" class="xg1">{$groupnames[$thread[tid]][name]}</a>]</span>

7
<!--{/if}-->

8
<!--{/if}-->




在下面增加这段:
[代码]php代码:
1
<!--{if $tbid && !$picnum == 0}--><span style="color:red;"><!--{$picnum}-->P</span><!--{/if}--></a>




这样修改就结束了
代码说明:
具体的图片显示多少这里↓,<3显示1,>2且<6显示3,>5显示6。

[代码]php代码:
1
<!--{if $picnum < 3}-->

2
<!--{eval $litpicnum = '1';}-->

3
<!--{elseif $picnum > 2 && $picnum < 6}-->

4
<!--{eval $litpicnum = '3';}-->

5
<!--{elseif $picnum > 5}-->

6
<!--{eval $litpicnum = '6';}-->

7
<!--{/if}-->





代码说明:
[代码]php代码:
1
<!--{if $litpicnum == 1}-->

2
<a href="forum.php?mod=viewthread&tid=$thread[tid]" class="z pipe" title="$thecover[aid]"><img src="data/attachment/forum/$thecover['attachment']" width="100" height="100"/></a>

3
<font class="z">This is what it is like to be with Trump.</font>

4
<!--{else}-->

5
<a href="forum.php?mod=viewthread&tid=$thread[tid]" class="z pipe" title="$thecover[aid]"><img src="data/attachment/forum/$thecover['attachment']" width="100" height="100"/></a>

6
<!--{/if}-->




如果图片数量等于1,后面带个摘要。
否则图片横排铺开。具体数量会按上面的显示。

通常情况下,两种样式即可,1图和多图,即1图显示在左右,多图在下面铺开。
如果多种样式,<!--{if $litpicnum == 数量}-->此数量时的表现形式</if>
当然,这的数量$litpicnum是受上面的代码中与$picnum关系的限定。
$picnum是实际总数量,$litpicnum是经过判断后允许显示的数量。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则