首页 >

实现dedecms自动给文章图片加alt标签

不废话,直接开始: 第一步:打开 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("\"".$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("\"".$this-Fields['title']."\" ",$this->Fields['imgurls']); 
第二步骤:没有了!搞定,收工! 注意,这个功能是对于生成html页面时起作用,也就是实现一个在生成时的替换功能。

  • 暂无相关文章