有好多站长在问如何让帖子列表显示帖内的附件图,调用数量可以随意设置,这里贴出方法
需要修改的文件,[color=#ff0000]template/default/forum/forumdisplay_list.htm[/color](这里以默认模板为例子,其他模板可以自行参考)
找到这段代码:
[code]<!--{loop $_G['forum_threadlist'] $key $thread}-->[/code]在下面增加这端代码:
[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]然后再查找到这段代码:
[code]<!-- end of table "forum_G[fid]" branch 1/3 -->[/code]其上最近的</tr>之后增加
[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]再查找:
[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]在下面增加这段:
[code]<!--{if $tbid && !$picnum == 0}--><span style="color:red;"><!--{$picnum}-->P</span><!--{/if}--></a>[/code]这样修改就结束了
代码说明:
具体的图片显示多少这里↓,<3显示1,>2且<6显示3,>5显示6。
[code]<!--{if $picnum < 3}-->
<!--{eval $litpicnum = '1';}-->
<!--{elseif $picnum > 2 && $picnum < 6}-->
<!--{eval $litpicnum = '3';}-->
<!--{elseif $picnum > 5}-->
<!--{eval $litpicnum = '6';}-->
<!--{/if}-->[/code]代码说明:
[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]如果图片数量等于1,后面带个摘要。
否则图片横排铺开。具体数量会按上面的显示。
通常情况下,两种样式即可,1图和多图,即1图显示在左右,多图在下面铺开。
如果多种样式,<!--{if $litpicnum == 数量}-->此数量时的表现形式</if>
当然,这的数量$litpicnum是受上面的代码中与$picnum关系的限定。
$picnum是实际总数量,$litpicnum是经过判断后允许显示的数量。
|