易优cms怎么替换图片alt为文章标题?
在extend/function.php里添加自己的修改方法:
//替换图片alt为文章标题function diy_replace_imgalt($title,$content){
$pattern = '/alt="*"/i';
preg_match_all($pattern,$content,$match);
//return var_dump($match);
if($match[0][0]=='alt=""'){
return preg_replace($pattern,"alt=$title",$content);
}
if($match[0][0]==null){
$pattern= '/<img */i';
preg_match_all($pattern,$content,$match);
return preg_replace($pattern,"<img alt=$title ",$content);
}
else{
return $content;
}
}
然后在view-article.htm里面调用函数{$eyou.field.title,$eyou.field.content|diy_replace_imgalt}
即可。