discuz!帖中图片附件添加alt描述的快捷方法

大家都是知道给图片<img>标签添加alt描述对于SEO的重要性,但是作为国内使用范围最广的discuz!论坛程序却默认没有添加alt描述,现在本文介绍一种简单的方法来帮助站长快速设置图片alt属性,方法如下:
打开模板文件:\template\default\forum\discuzcode.htm
找到如下代码(discuz! X3.2大概在257行左右,其他版本请自行搜索):

  1. <!–{if $_G[‘setting’][‘thumbstatus’] && $attach[‘thumb’]}–>
  2.         <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" οnclick="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’} οnmοuseοver="showMenu({‘ctrlid’:this.id,’pos’:’12’})"{/if} />
  3. <!–{else}–>
  4.         <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’} οnmοuseοver="showMenu({‘ctrlid’:this.id,’pos’:’12’})"{/if} />
  5. <!–{/if}–>

复制代码

改成:

  1. <!–{if $_G[‘setting’][‘thumbstatus’] && $attach[‘thumb’]}–>
  2.         <img alt="{if $attach[‘description’]}$attach[‘description’]{else}$_G[‘thread’][‘subject’]{/if}"{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" οnclick="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’} οnmοuseοver="showMenu({‘ctrlid’:this.id,’pos’:’12’})"{/if} />
  3. <!–{else}–>
  4.         <img alt="{if $attach[‘description’]}$attach[‘description’]{else}$_G[‘thread’][‘subject’]{/if}"{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’} οnmοuseοver="showMenu({‘ctrlid’:this.id,’pos’:’12’})"{/if} />
  5. <!–{/if}–>

复制代码

在inpost="1"{if $_GET[‘from’] != ‘preview’} 后面添加,alt="$attach[imgalt]" title="$attach[imgalt]",就可以啦!!$_G[forum_thread][subject]  文章标题
$_G[setting][sitename] 网站名称
$attach[imgalt] 图片名称

温馨提示:本文最后更新于2022-09-12 12:07:01,某些文章具有时效性,若有错误或已失效,请在下方留言或联系丁塔克博客
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论