网站想要更好的适应搜索引擎的话, 就要把最基础的一些小优化标签做好,
虽然说现在搜索都很厉害能够识别图片, 但是除非的你的图片每一张都是周杰伦、范冰冰等知名图片。。。
不然你还是要给你自己的图添加 alt 标签能搜索引擎去识别的。
整个网站那么多帖子图片,我不可能一个个去添加吧,要死人的。
没有叫你一个个去加,现在就是教你全站帖子图片自动添加 alt 标签。
首先找到:/template/你的模板/forum/discuzcode.htm 文件,如果你使用的模板没有这个文件,不要嚷嚷,没有是正常的。只是有些特别的会有。没有的的话就去默认的模板下:/template/default/forum/discuzcode.htm文件
3.2 正确的改法是有两处是需要修改的,有两处是需要添加的。
1. 第一处修改大法;
是先找到 直接搜索 <!--{if $_G
- <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>
找到之后改成
- <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]" title="$attach[imgalt]" 改成了 alt="$_G[forum_thread][subject]- $_G[setting][sitename] " title="$_G[forum_thread][subject]- $_G[setting][sitename] " 而已。
说明一下 $_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}-->
找到之后修改成
- <!--{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[forum_thread][subject]- $_G[setting][sitename] " title="$_G[forum_thread][subject]- $_G[setting][sitename] " 这个代码而已。
改好之后直接替换回去。更新 css 缓存之类的。