织梦怎么让文章中图片自动添加ALT属性

打开/include/extend.func.php文件 在最下面加入: //文章body优化替换 function replaceurl($newurl) { global $dsql,$id; //获取图片附加表imgurls字段内容进行处 $row = $dsql-GetOne(SELECT title FROM dede_archives where id=$id); //替换图片Alt为文档
打开/include/extend.func.php文件
 
在最下面加入:
 
//文章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属性就把上面代码修改成下面的代码
 
//文章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;
     }

 
 
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

织梦生成静态html页面时报错:Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /wwwroot/include/helpers/string.helper.php on line 121 字面意思理解是内存不足,很多朋友可能认为是内存不足问题,实际上不
有时候我们的文档特别的多,另外也是为防止网站被采集,全站文章被索引,所以要控制下织梦dedecms列表页面数量。 这样的话我们要具体怎么操作呢? 1、首先建立一个全局变量: 在系统-站点设置中添加一个新的变量,变量名称:cfg_listmaxpage,变量说明:栏目
dedecms织梦的全局变量可以在/include/common.inc.php文件中看到,此文件内定义了大量的全局变量,详细自己去看看。 如果我们要实用dedeCMS织梦全局变量该如何调用: 第一种单独调用: {dede:global.变量名 /},注意闭合,否则会以文本形式输出。这种一般适用
织梦DEDECMS 栏目文章文章命名规则修改, 每次添加栏目的时候 都要改文章命名规则,十分麻烦, 修改下面这个地方就可以一改永亦,织梦模板网为您解答 找到\include\common.inc.php 搜索 $cfg_df_namerule 把: $cfg_df_namerule = {typedir}/{Y}/{M}{D}/{aid
当我们通过{dede:arclist keyword=关键词}来调用文章列表时,你会发现只在其中一个栏目里生效,在其他栏目,仍然显示上一次的关键词。 原因是由于arclist的缓存导致的。 只需修改/include/taglib/arclist.lib.php文件,大概在384行: $taghash = md5(seriali
我们在使用织梦dedecms数据库内容替换时候,经常遇到 安全码 显示的无法识别或者不清晰,这个安全码的位置是在核心 - 批量维护 - 数据库内容替换,如果识别不了,这个页面还没有改变验证码的地方,只能重新刷新页面,如果我们不想要这个安全码的话,要怎么操