搜索
查看: 873|回复: 0
打印 上一主题 下一主题

discuz3.4帖中图片附件添加alt描述的快捷方法

[复制链接]
跳转到指定楼层
楼主
发表于 2017-8-24 12:46:41 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
大家都是知道给图片<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" 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} />  
  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'} onmouseover="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" 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} />  
  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'} onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})"{/if} />  
  5. <!--{/if}-->  
复制代码

修改结果:
1、当图片附件有文字描述的时候调用该描述至alt;
2、当没有文字描述的时候调用帖子标题至alt;



【*】注意以上修改代码时请注意使用代码编辑器,不要再记事本中修改,切记!



本站可以由注册用户自行上传图片或附件,无法鉴别所上传图片或附件的知识版权,如果侵犯,请及时通知我们,本博客将在第一时间及时删除。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

麦屯网

网站简介:专业发烧音乐试听,最新专辑,发烧器材评测,音乐影视信息交流。

联系我们

  • 反馈邮箱:sorry16817#gmail.com

麦屯博客 |网站地图

Powered by maitun.net

快速回复 返回顶部 返回列表