图片没有alt标签一张一张写相当麻烦,找到文章内容页标签里的{dede:field.body/}
替换成以下代码即可实现根据文章标题自动补全图片ALT属性和TITLE属性,完美解决手动问题。
{dede:field.body runphp=yes}
global $dsql,$id,$aid;
$myid = isset($id) ? $id : $aid;
$row = $dsql->GetOne("SELECT title FROM #@__archives WHERE id=$myid");
$title = $row['title'];
$str = @me;
$search = '/(?)alt=(["\'])?.?(?(2)\2|\s)([^>]+>)/is';
$search1 = '/(?)title=(["\'])?.?(?(2)\2|\s)([^>]+>)/is';
$content = preg_replace($search,'$1$3',$str);
$content = preg_replace($search1,'$1$3',$content);
@me = str_replace('<img', "<img alt='{$title}' title='{$title}'", $content);
{/dede:field.body}
最终实现的效果: