帝国cms后台发布内容自动把内容图片的alt和title替换为文章标题

帝国cms后台发布内容自动把内容图片的alt和title替换为文章标题

游戏|数码彩彩2024-02-18 7:38:28328A+A-

操作方法如下:

1.把下面的代码放到/e/class/userfun.php (放到最后?>的前面)

function user_imgalt($mid,$f,$isadd,$isq,$value,$cs){
$title=$_POST['title'];
$htmls=$value;
$pattern = "/<img[^>]+>/"; 
preg_match_all($pattern, $htmls, $matches); 
for ($i=0; $i<=count($matches[0]); $i++) {
  preg_match_all("/alt=".+?"/",$matches[0][$i],$altimg); 
  preg_match_all("/title=".+?"/",$matches[0][$i],$titleimg); 
$t_alt=count($altimg[0]);
if($t_alt==0){
$htmls=str_replace("<img","<img alt="{$title}"",$htmls);
$htmls=str_replace("<img","<img title="{$title}"",$htmls);
}
}   
return $htmls;
}

2.在模型里正文字段一般是newstext(也可以是其它字段),在字段处理函数文本框填上user_imgalt 如下图:

帝国cms后台发布内容自动把内容图片的alt和title替换为文章标题

3.这样在帝国cms后台发布信息的时候就可以自动替换图片alt和title属性为信息标题了!

点击这里复制本文地址 版权声明:本文内容由网友提供,该文观点仅代表作者本人。本站(https://www.angyang.net.cn)仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

昂扬百科 © All Rights Reserved.  渝ICP备2023000803号-3网赚杂谈