"景先生毕设|www.jxszl.com

DEDE给文章图片增加alt属性与title属性

2023-09-12 15:40编辑: www.jxszl.com景先生毕设
DEDE给文章内容页图片增加alt 属性与 title 属性

找到文件/ include/arc.archives.class.php 打开查找下面的代码:大概在230行左右
 //设置全局环境变量
            $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
            @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$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['title']."(www.itemperor.com)'title='".$this->Fields['title']."' ",$this->Fields['body']);

-----------------------------------------------------------------------------------------------
注:添加时请将上面代码中的“删除”这两个字去掉,
同时将网址www.itemperor.com 改为你自己的网站或者标题
如果只需要alt属性,不需要title属性的话,删除 title='".$this->Fields['title']."' 即可.


原文链接:http://www.jxszl.com/biancheng/dedecms/447247.html