Discuz! 3.3全站帖子自动添加图片alt标签
网站想要更好的适应搜索引擎的话,就要把最基础的一些小优化标签做好,
虽然说现在搜索都很厉害能够识别图片,但是除非的你的图片每一张都是周杰伦、范冰冰等知名图片。。。
不然你还是要给你自己的图添加alt标签能搜索引擎去识别的。
整个网站那么多帖子图片,我不可能一个个去添加吧,要死人的。
没有叫你一个个去加,现在就是教你全站帖子图片自动添加alt标签。
首先找到:/template/你的模板/forum/discuzcode.htm文件,如果你使用的模板没有这个文件,不要嚷嚷,没有是正常的。只是有些特别的会有。没有的的话就去默认的模板下:/template/default/forum/discuzcode.htm文件
3.2正确的改法是有两处是需要修改的,有两处是需要添加的。
1.第一处修改大法;
是先找到 直接搜索 <!--{if attach['thumb']}--> 得到的第一个里面有两个这样的差不多代码。对比下下面。
1 2 3 4 5 6 7 | <div class = "mbn savephotop" > <!--{ if $_G[ 'setting' ][ 'thumbstatus' ] && $attach[ 'thumb' ]}--> <a href= "javascript:;" ><img id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" onclick= "zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[setting][showexif]}')" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" alt= "$attach[imgalt]" title= "$attach[imgalt]" w= "$attach[width]" /></a> <!--{ else }--> <img id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode alt= "$attach[imgalt]" title= "$attach[imgalt]" w= "$attach[width]" /> <!--{/ if }--> </div> |
找到之后改成
1 2 3 4 5 6 7 | <div class = "mbn savephotop" > <!--{ if $_G[ 'setting' ][ 'thumbstatus' ] && $attach[ 'thumb' ]}--> <a href= "javascript:;" ><img id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" onclick= "zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[setting][showexif]}')" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" alt= "$_G[forum_thread][subject]- $_G[setting][sitename] " title= "$_G[forum_thread][subject]- $_G[setting][sitename] " w= "$attach[width]" /></a> <!--{ else }--> <img id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode alt= "$_G[forum_thread][subject]- $_G[setting][sitename] " title= "$_G[forum_thread][subject]- $_G[setting][sitename] " w= "$attach[width]" /> <!--{/ if }--> </div> |
其实就是把 alt="attach[imgalt]" 改成了 alt="_G[setting][sitename] " title="_G[setting][sitename] " 而已。
说明一下 _G[setting][sitename] 这个标签的意思是 帖子标题-网站名称 的意思,如果你不想要网站名称的带横杠删掉后面的就可以。
2.添加大法
这个真不是很好找,你干脆也一样直接 搜索 <!--{if attach['thumb']}--> 是第二个得到的第二个,反正是底下的一个,要看清楚点。
1 2 3 4 5 | <!--{ if $_G[ 'setting' ][ 'thumbstatus' ] && $attach[ 'thumb' ]}--> <img{ if $attach[ 'price' ] && $_G[ 'forum_attachmentdown' ] && $_G[ 'uid' ] != $attach[ 'uid' ]} class = "attprice" {/ if } style= "cursor:pointer" id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" onclick= "zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[setting][showexif]}')" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" inpost= "1" { if $_GET[ 'from' ] != 'preview' } onmouseover= "showMenu({'ctrlid':this.id,'pos':'12'})" {/ if } /> <!--{ else }--> <img{ if $attach[ 'price' ] && $_G[ 'forum_attachmentdown' ] && $_G[ 'uid' ] != $attach[ 'uid' ]} class = "attprice" {/ if } id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode id= "aimg_$attach[aid]" inpost= "1" { if $_GET[ 'from' ] != 'preview' } onmouseover= "showMenu({'ctrlid':this.id,'pos':'12'})" {/ if } /> <!--{/ if }--> |
找到之后修改成
1 2 3 4 5 6 | <!--{ if $_G[ 'setting' ][ 'thumbstatus' ] && $attach[ 'thumb' ]}--> <img{ if $attach[ 'price' ] && $_G[ 'forum_attachmentdown' ] && $_G[ 'uid' ] != $attach[ 'uid' ]} class = "attprice" {/ if } style= "cursor:pointer" id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" onclick= "zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[setting][showexif]}')" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode{else}{$attach[url]}$attachthumb{/if}" alt= "$_G[forum_thread][subject]- $_G[setting][sitename] " title= "$_G[forum_thread][subject]- $_G[setting][sitename] " inpost= "1" { if $_GET[ 'from' ] != 'preview' } onmouseover= "showMenu({'ctrlid':this.id,'pos':'12'})" {/ if } /> <!--{ else }--> <img{ if $attach[ 'price' ] && $_G[ 'forum_attachmentdown' ] && $_G[ 'uid' ] != $attach[ 'uid' ]} class = "attprice" {/ if } id= "aimg_$attach[aid]" aid= "$attach[aid]" src= "{STATICURL}image/common/none.gif" zoomfile= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes¬humb=yes{else}{$attach[url]}$attach[attachment]{/if}" file= "{if $attach[refcheck]}forum.php?mod=attachment{$is_archive}&aid=$aidencode&noupdate=yes{else}{$attach[url]}$attach[attachment]{/if}" $widthcode alt= "$_G[forum_thread][subject]- $_G[setting][sitename] " title= "$_G[forum_thread][subject]- $_G[setting][sitename] " id= "aimg_$attach[aid]" inpost= "1" { if $_GET[ 'from' ] != 'preview' } onmouseover= "showMenu({'ctrlid':this.id,'pos':'12'})" {/ if } /> <!--{/ if }--> |
其实就是往代码里面添加了 alt="_G[setting][sitename] " title="_G[setting][sitename] " 这个代码而已。
改好之后直接替换回去。更新css缓存之类的
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具