Denki 發表於 2021年3月3日 21:52:53

讓DISCUZ論壇主題和門戶文章中的圖片自動居中的方法

在網上看到很多站長想帖子及文章中的圖片自動居中,但沒有找到相關方法,且官方的方法貌似只能通過編輯器中居中的那個標誌手動居中,好吧,福利來了修改這個文件中的兩處地方就可以實現全文圖片自動居中啦。修改的文件:template/default/forum/discuzcode.php和template/default/common/module.css如果不是默認的模板,請尋找所選模板的相應目錄。

修改的方法:

1、找到258行以下代碼:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} style="cursor:pointer" id="aimg_$attach" aid="$attach" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach}$attach{/if}" file="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach}$attachthumb{/if}" inpost="1"{if $_GET['from'] != 'preview'}{/if} />
修改為:

<div style="text-align:center;"><img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} style="cursor:pointer" id="aimg_$attach" aid="$attach" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach}$attach{/if}" file="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach}$attachthumb{/if}" inpost="1"{if $_GET['from'] != 'preview'}{/if} /></div>



2、找到260行的以下代碼:

<img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} id="aimg_$attach" aid="$attach" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach}$attach{/if}" file="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach}$attach{/if}" $widthcode id="aimg_$attach" inpost="1"{if $_GET['from'] != 'preview'}{/if} />
修改為:

<div style="text-align:center;"><img{if $attach['price'] && $_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']} class="attprice"{/if} id="aimg_$attach" aid="$attach" src="{STATICURL}image/common/none.gif" zoomfile="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach}$attach{/if}" file="{if $attach}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach}$attach{/if}" $widthcode id="aimg_$attach" inpost="1"{if $_GET['from'] != 'preview'}{/if} /></div>



3、門戶中文章居中的方法找到template/default/common/module.css文件中第1317行,



.zoom { cursor: pointer; }
改為

.zoom { cursor: pointer;display: block;margin: auto; }
頁: [1]
檢視完整版本: 讓DISCUZ論壇主題和門戶文章中的圖片自動居中的方法