织梦网站技术教程网让你更全面的了解和使用织梦cms

当前位置:织梦教程网 > 织梦二次开发 > DedeCMS文章里图片ALT注释自动填充为文章标题

DedeCMS文章里图片ALT注释自动填充为文章标题

已有人收藏发布时间:2018-10-17 10:48   来源:www.dedejc.com 作者:织梦教程网

首先找到文件 \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['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']);
}
另一个写法
//设置全局环境变量
   $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("<img " ,"<img alt='".$this->Fields['title'].",cms资源网dedejs.com",$this->Fields['body']);
            $this->Fields['imgurls'] = str_ireplace("<img " ,"<img alt='".$this->Fields['title'].",cms资源网dedejs.com' ",$this->Fields['imgurls']);
            $this->Fields['introduce'] = str_ireplace("<img " ,"<img alt='".$this->Fields['title'].",cms资源网dedejs.com' ",$this->Fields['introduce']); 
  }  

将以上代码替换完成后,更新文档HTML,就可以了。

标签: dedecms图片alt注释