网站用标签实现图片自动Alt功能
第一步,在织梦dedecms网站的根目录下,打开源代码文件:Include/ arc.archives.class.php
第二步,在这个文件中查找下面的代码:
- @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
第三步:把上面这段代码修改为下面代码:
- $this->Fields['body'] = str_ireplace(array('altalt=""','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('altalt=""','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']);
第四步,保存文件刷新