discuz x3.4/x3.3帖子列表頁調用帖子內容圖片附件(多圖)
1、找到forum/forumdisplay_list.htm文件,打開并按照以下方法進行編輯;
2、打開forumdisplay_list.htm文件后,找到
- <!--{loop $_G['forum_threadlist'] $key $thread}-->
復制代碼 代碼,在其下添加:
- <!--{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}-->
復制代碼 3、在forumdisplay_list.htm中繼續找到
- <!-- end of table "forum_G[fid]" branch 1/3 -->
復制代碼 在這段代碼上方找到最靠近的</tr>,在此之后添加:
- <!--{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}-->
復制代碼 4、繼續找到:
- <!--{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}-->
復制代碼 在之后添加
- <!--{if $tbid && !$picnum == 0}--><span style="color:red;"><!--{$picnum}-->P</span><!--{/if}--></a>
復制代碼 保存后完成!效果如下圖所示。
捕獲.PNG (464.33 KB, 下載次數: 10)
下載附件
2024-3-20 22:30 上傳
【代碼分析】:
1、上面介紹的代碼中,有一段是設置圖片顯示數量的邏輯代碼,如下
- <!--{if $picnum < 3}-->
- <!--{eval $litpicnum = '1';}-->
- <!--{elseif $picnum > 2 && $picnum < 6}-->
- <!--{eval $litpicnum = '3';}-->
- <!--{elseif $picnum > 5}-->
- <!--{eval $litpicnum = '6';}-->
復制代碼 意思是當內容中圖片數量小于3時,顯示1張圖片;
當圖片數量大于2小于6時,圖片顯示3張;
當圖片數量大于5時,顯示6張圖片。大家可以按照需求進行修改。
2、代碼中設置的圖片長和寬都是100px,width="100" height="100"如果有需要可以按照自己的想法修改數值。
|