打开/include/extend.func.php文件 在最下面加入: //文章body优化替换 function replaceurl($newurl) { global $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql-GetOne(SELECT title FROM wmd_archives where
打开/include/extend.func.php文件
在最下面加入:
//文章body优化替换
function replaceurl($newurl)
{
global $dsql,$id;
//获取图片附加表imgurls字段内容进行处
$row = $dsql->GetOne("SELECT title FROM wmd_archives where id=$id");
//替换图片Alt为文档标题
$newurl=str_ireplace(array('alt=""','alt=\'\''),'',$newurl);
$newurl=preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img alt=\"".$row['title']."\"",$newurl);
//去掉结尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
}
前端调用代码:
{dede:field.body function='replaceurl(@me)'/}
需要图片中的style width height属性就把上面代码修改成下面的代码
//文章body优化替换
function replaceurl($newurl)
{
global $dsql,$id;
//获取图片附加表imgurls字段内容进行处
$row = $dsql->GetOne("SELECT title FROM wmd_archives where id=$id");
//去掉img的width和height
$newurl=preg_replace('/style=\"width\:(.*)\"/','',$newurl);
//替换图片Alt为文档标题
$newurl=str_ireplace(array('alt=""','alt=\'\''),'',$newurl);
$newurl=preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img alt=\"".$row['title']."\"",$newurl);
//去掉结尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
}
织梦狗模板
织梦dedecms怎么让文章中图片自动添加ALT属性


最新VIP资源
猜你喜欢
- 织梦DEDECMS如何修改缩略图地址长度 2023-10-08
- 织梦dedecms禁止会员发布文章内容带超级链接 2023-10-07
- 织梦dedecms列表循环判断增加样式的办法 2023-09-16
- dedecms织梦列表中单独显示共有多少条数据的办法 2023-09-23
- windows系统配置nginx环境运行pbootcms访问首页直接404的问题 2023-11-24
- 织梦dedecms文章内容中怎么替换多个敏感字词 2023-08-20
- 织梦DEDECMS软件模型编辑器不实用的修改方法 2023-10-25
- dedecms织梦通过文档的标题获取文档的链接 2023-09-29
- 织梦dede:flink标签支持limit属性的方法 2023-08-06
- 织梦在一个标签中调用两个字段的办法 2023-10-08