织梦怎么让文章中图片自动添加ALT属性
打开/include/extend.func.php文件
在最下面加入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//文章body优化替换 function replaceurl($newurl) { global $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql->GetOne("SELECT title FROM dede_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属性就把上面代码修改成下面的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//文章body优化替换 function replaceurl($newurl) { global $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql->GetOne("SELECT title FROM dede_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; } |
①本站所有织梦模板资源均来自用户分享和网络收集,如果侵犯了您的权益,请联系网站客服处理
②本站提供的织梦源码,均带数据及演示地址。可以在任一源码详情页查看演示地址。
③由于博主时间紧缺,所有模板源码不提供技术支持。仅部分收费原创源码提供售后
④如遇模板源码下载链接打不开或者有错误,请联系网站客服QQ指出纠正。
⑤人民币与金币汇率为1比1,即1元=1金币
织梦楼 » 织梦怎么让文章中图片自动添加ALT属性
织梦楼 » 织梦怎么让文章中图片自动添加ALT属性