如何给dedecms文章里自动添加图片ALT属性
我们打开Include/ arc.archives.class.php
查找:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">@SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');</span></span>
在上面代码后面添加:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">//替换图片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['title']."' ",$this->Fields['body']);</span></span>
上面是修改默认的模板标签:{dede:field.body/} ,如果是其它字段,可以修改$this->Fields[‘body’] 为其它的字段名。
0条评论