请选择 进入手机版 | 继续访问电脑版

discuz帖子列表页如何调用帖子图片附件缩略图(附详情)

[复制链接]
树苗收集系 发表于 2019-11-23 19:29:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
[color=#000][font="]有好多[/font][/color][font="]站长[/font][color=#000][font="]在问如何让帖子列表显示帖内的附件图,调用数量可以随意设置,这里贴出方法:[/font][/color] 1.jpg

[align=left][color=#000][font=&quot;]需要修改的文件,template/default/forum/forumdisplay_list.htm(这里以默认[color=rgb(68, 68, 68) !important][url=http://www.dtyuanma.com/forum-2-1.html]模板[/url][/font]为例子,其他模板可以自行参考)[/color][/align][align=left][color=#000][font=&quot;]找到这段代码:[/font][/color][/align][code]<!--{loop $_G['forum_threadlist'] $key $thread}-->
[/code][color=#000][font=&quot;]在下面增加这端代码:[/font][/color]
[code]<!--{eval $tbid = DB::result(DB::query("SELECT tableid FROM ".DB::table('forum_attachment')." WHERE `tid`= '$thread[tid]'"));}-->
<!--{if $tbid}-->
<!--{eval $picount = DB::fetch_all("SELECT aid FROM ".DB::table('forum_attachment_'.$tbid.'')." WHERE `tid`= '$thread[tid]' AND `isimage`=1;");}-->
<!--{eval $picnum = count($picount);}-->
<!--{if $picnum < 3}-->
<!--{eval $litpicnum = '1';}-->
<!--{elseif $picnum > 2 && $picnum < 6}-->
<!--{eval $litpicnum = '3';}-->
<!--{elseif $picnum > 5}-->
<!--{eval $litpicnum = '6';}-->
<!--{/if}-->
<!--{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;");}-->
<!--{/if}-->
[/code][color=#000][font=&quot;]然后再查找到这段代码:[/font][/color]
[code]<!-- end of table "forum_G[fid]" branch 1/3 -->
[/code][color=#222527][font=Helvetica, Arial, &quot;]其上最近的</tr>之后增加[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;][code]<!--{if $tbid}-->
<tr>
<td></td>
<td></td>
<td colspan="4">
<!--{loop $covers $thecover}-->
<!--{if $litpicnum == 1}-->
<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>
<font class="z">This is what it is like to be with Trump.</font>
<!--{else}-->
<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>
<!--{/if}-->
<!--{/loop}-->
</td>
</tr>
<!--{/if}-->
[/code]再查找:[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;][code]<!--{if !$thread['forumstick'] && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])}-->
<!--{if $thread['related_group'] == 0 && $thread['closed'] > 1}-->
<!--{eval $thread[tid]=$thread[closed];}-->
<!--{/if}-->
<!--{if $groupnames[$thread[tid]]}-->
<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>
<!--{/if}-->
<!--{/if}-->
[/code]在下面增加这段:[/font][/color][color=#222527][font=Helvetica, Arial][hide][/font][/color][font=Helvetica, Arial][color=#222527]
[/color][/font][color=#222527][font=Helvetica, Arial, &quot;][code]<!--{if $tbid && !$picnum == 0}--><span style="color:red;"><!--{$picnum}-->P</span><!--{/if}--></a>
[/code][indent][/hide][/indent]
[/font][/color][color=#222527][font=Helvetica, Arial, &quot;]这样修改就结束了[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;]----------以下为代码说明---------[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;][code]<!--{if $picnum < 3}-->
<!--{eval $litpicnum = '1';}-->
<!--{elseif $picnum > 2 && $picnum < 6}-->
<!--{eval $litpicnum = '3';}-->
<!--{elseif $picnum > 5}-->
<!--{eval $litpicnum = '6';}-->
<!--{/if}-->[/code]具体的图片显示多少这里↓,<3显示1,>2且<6显示3,>5显示6。[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;]
[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;]----------[/font][/color][color=#000][font=&quot;]以下为[/font][/color][color=#000][font=&quot;]代码说明---------[/font][/color]
[color=#222527][font=Helvetica, Arial, &quot;][code]<!--{if $litpicnum == 1}-->
<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>
<font class="z">This is what it is like to be with Trump.</font>
<!--{else}-->
<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>
<!--{/if}-->[/code][/font][/color][color=#222527][font=Helvetica, Arial, &quot;]如果图片数量等于1,后面带个摘要。
否则图片横排铺开。具体数量会按上面的显示。

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

回复

使用道具 举报

精彩评论3

淡看红尘轻笑孤 发表于 2019-12-7 20:25:03 | 显示全部楼层
非常不错,感谢分享!
回复

使用道具 举报

树上的向日葵 发表于 2021-3-13 18:44:53 | 显示全部楼层
我表示压力很大
回复

使用道具 举报

树上的向日葵 发表于 2022-6-18 17:04:43 | 显示全部楼层
前来围观,LZ好样的!
回复

使用道具 举报

发布主题
推荐阅读 更多
阅读排行 更多
广告位
全国统一客服电话
400-1234-5678

24x7小时免费咨询

  • 官方在线客服

    QQ客服:小西

    点击交谈

    QQ客服:良子

    点击交谈

    QQ客服:闵月

    点击交谈
  • 安徽省合肥市高新区创新产业园

  • 手机扫码查看手机版

    手机查找资源更方便

  • 扫一扫关注官方微信

    加入官方微信群