小华

【本人实测】DZ全站帖子自动添加图片alt标签

作者:小华   发布时间:2017-12-07 15:29   回复数:14   浏览数:2722
小华
272214小华未验证会员
热门 2017-12-07 15:29:39
272214 热门 2017-12-07 15:29:39
演示如下:

图片:1.png



图片:2.png



网站想要更好的适应搜索引擎的话,就要把最基础的一些小优化标签做好,

虽然说现在搜索都很厉害能够识别图片,但是除非的你的图片每一张都是周杰伦、范冰冰等知名图片。。。

不然你还是要给你自己的图添加alt标签能搜索引擎去识别的。

整个网站那么多帖子图片,我不可能一个个去添加吧,要死人的。

没有叫你一个个去加,现在就是教你全站帖子图片自动添加alt标签。

首先找到:/template/你的模板/forum/discuzcode.htm文件,如果你使用的模板没有这个文件就去默认的模板下:/template/default/forum/discuzcode.htm文件

3.2正确的改法是有两处是需要修改的,有两处是需要添加的。

1.第一处修改;
是先找到 直接搜索<!--{if $_G['setting']['thumbstatus'] && $attach['thumb']}-->得到的第一个里面有两个这样的差不多代码。对比下下面。                                                <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>修改成
本部分内容设定了隐藏,需要回复后才能看到

说明一下 $_G[forum_thread][subject]- $_G[setting][sitename]   这个标签的意思是  帖子标题-网站名称 的意思,如果你不想要网站名称的,直接将带横杠删掉后面的就可以。

2.第二处修改: 搜索<!--{if $_G['setting']['thumbstatus'] && $attach['thumb']}-->将搜索到的两处代码替换为以下代码。                                                <!--{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}-->
修改成
本部分内容设定了隐藏,需要回复后才能看到


3.第三处修改:
搜索代码$attach[filename]修改为:
本部分内容设定了隐藏,需要回复后才能看到


备注:此方法跟文件基于3.2来修改,其他版本请自行测试。测试前请备份好文件。


DZ站长交流群:493651246



168520
沙发168520禁止发言 2017-12-19 22:22
用户被禁言,该主题自动屏蔽!
man_20007
板凳man_20007终身ViP 2017-12-26 19:09
谢谢分享,有门户自动添加alt的教程吗
害怕了
地板害怕了学习ViP(审查中) 2018-01-19 09:39
好东东都要学习
银滩V网事
4楼银滩V网事步入草根 2018-02-25 16:34
不错,学习下
渐入佳境123
5楼渐入佳境123年费ViP 2018-03-27 11:34
DZ全站帖子自动添加图片alt标签
路过人间
6楼路过人间步入草根 2018-05-31 21:24
这个有需要的啊。。。
乘风破浪
7楼乘风破浪步入草根 2018-06-29 18:29
学习了。。。。。
小志UZI
8楼小志UZI步入草根 2018-07-09 19:50
感谢分享 我试试
地势坤
9楼地势坤步入草根 2018-07-14 13:50
现场V型中v
夏天的小小风
10楼夏天的小小风步入草根 2018-07-19 11:35
很不错的文昌
456网赚官方认证
11楼456网赚官方认证步入草根 2018-09-15 19:04
RE: 【本人实测】DZ全站帖子自动添加图片alt标签 [修改]
圣光
12楼圣光终身ViP 2018-10-07 00:03
【本人实测】DZ全站帖子自动添加图片alt标签 [修改]
yrkjssg
13楼yrkjssg步入草根 2018-10-15 22:33
不错  学习一下
王众
14楼王众步入草根 2018-11-07 10:12
我来学习下
游客
登录后才可以回帖,登录 或者 注册