帝国cms文章内容图片不会自动添加ait值,而alt是图像描述性文本,在seo优化中有很重要的地位。为了增强图片seo的权重,往往会给图片添加alt属性。那么帝国cms文章页面图片如何自动为图片添加文章标题的alt值呢?
具体实现方法如下:
1、修改系统模型正文字段newstext
路径:后台--系统-系统设置-数据表与系统模型--管理数据表--管理字段--newstext--修改--添加user_imgalt
如图:
2、userfun.php文件添加以下函数
路径:/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;
- }