对付一个SEO好手来说,每个细节都相当重要。本文先容如何将文章里的图片的注释改成文章标题,如此一来,对搜索引擎会越发友好。假如只想加文章的就把带imgurls的三行去掉即可。
修改文件:Include/ arc.archives.class.php
查找以下代码:
$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];@SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
在以下添加代码:
$this->Fields['body'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['body']);$this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']);
$this->Fields['body'] = str_ireplace("<img " ,"<img alt=\"".$this->Fields['title']."\" ",$this->Fields['body']);
$this->Fields['imgurls'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['imgurls']);
$this->Fields['imgurls'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['imgurls']);
$this->Fields['imgurls'] = str_ireplace("<img " ,"<img alt=\"".$this->Fields['title']."\" ",$this->Fields['imgurls']);
//替换图片Alt为文档标题
改完今后直接生玉成站就OK了,对图片多的站来说照旧很重要的,图片的alt标签不容忽视。生成今后我发明一个问题,就是图片的注酿成了alt='文章标题' 可是百度的类型应该是 alt="文章标题"。
办理要领: 你代码的最后一行
$this->Fields['body'] = str_ireplace("<img " ,"<img alt='".$this->Fields['title']."' ",$this->Fields['body']);改为
$this->Fields['body'] = str_ireplace("<img " ,"<img alt=\"".$this->Fields['title']."\" ",$this->Fields['body']);单引号改为双引号并在前面加 \
DEDECMS下载
织梦CMS(DedeCMS) v5.7 SP1 GBK build20150618下载