找回密码
 立即注册

QQ登录

只需一步,快速开始

万卷论坛-万卷网

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

[复制链接]

发表于 2018-1-11 15:24:01 | 显示全部楼层 |阅读模式
大家都是知道给图片标签添加alt描述对于SEO的重要性,但是作为国内使用范围最广的discuz!论坛程序却默认没有添加alt描述,现在本文介绍一种简单的方法来帮助站长快速设置图片alt属性,方法如下:
打开模板文件:\template\default\forum\discuzcode.htm
找到如下代码(discuz! X3.2大概在257行左右,其他版本请自行搜索):
[html] view plain copy print?

  • <!--{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" 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'}{/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'}{/if} />
  • <!--{/if}-->

<!--{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" 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'}{/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'}{/if} /><!--{/if}-->

改成下面的:
[html] view plain copy print?

  • <!--{if $_G['setting']['thumbstatus'] && $attach['thumb']}-->
  •     <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" 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'}{/if} />
  • <!--{else}-->
  •     <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'}{/if} />
  • <!--{/if}-->

<!--{if $_G['setting']['thumbstatus'] && $attach['thumb']}-->        <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" 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'}{/if} /><!--{else}-->        <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'}{/if} /><!--{/if}-->

修改结果:
1、当图片附件有文字描述的时候调用该描述至alt;
2、当没有文字描述的时候调用帖子标题至alt;  
【*】注意以上修改代码时请注意使用代码编辑器,不要再记事本中修改,切记!

温馨提示:
1、万卷书店现有正版新书,二手书,电子书。当您有需要购买时请联系QQ:2328858568 微信:a15319999845给您查询处理。注明:万卷论坛。有优惠
2、论坛已开通免费注册。当您在访问万卷论坛中遇到问题,投诉邮箱:673665010@qq.com 第一时间给您回复处理。




上一篇:Discuz!UCenter创始人密码重置方法
下一篇:Discuz!X3.4最新版完美解决帖子标题限制80个字符的问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

资讯网--资讯科技信息网站|网站地图

Processed in 0.081016 second(s), 30 queries.

站点统计| 举报| Archiver| 手机版| 小黑屋

Powered by Discuz! X3.4 © 2001-2018 Comsenz Inc.

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

Honor accompaniments. theme macfee

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