用DedeCMS在做图片站,一般都是采集,很多图片没有alt标签,对搜索引擎来说并不友好,一张一张写相当麻烦,可以修改为文档关键字或文章标题作为图片alt描述。图片的匹配度当然没有手动的好,但做站群的时候能省事就好。

修改文件include/arc.archives.class.php

找到

//设置全局环境变量
$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');

在下面增加代码

//替换图片Alt为文档关键字+标题
$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['keywords']." . ".$this->Fields['title']."' ",$this->Fields['body']);
//end

重新生成文章即可,如果是其它字段,可以修改$this->Fields['body'] 为其它的字段名。

免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。