帝国CMS图片添加alt教程:自动把内容图片alt和title属性替换为信息标题

2018-06-2713:44:56网站建设与开发Comments1,979 views字数 662阅读模式

发表文章内容时,帝国cms自动把内容图片alt和title属性替换为信息标题。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3840.html

操作方法如下:
1.把下面的代码放到/e/class/userfun.php   (放到最后?>的前面)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3840.html

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;
}文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3840.html

2.在模型里正文字段一般是newstext(也可以是其它字段),在字段处理函数文本框填上user_imgalt 如下图:
帝国CMS图片添加alt教程:自动把内容图片alt和title属性替换为信息标题文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3840.html

3.发布信息的时候就可以自动替换图片alt和title属性为信息标题了!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/3840.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/3840.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定