打開Include/?arc.archives.class.php
查找:
@SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
在上面代碼后面添加:
//替換圖片Alt和title為文檔標(biāo)題 $this->Fields['body'] = str_ireplace(array('altalt=""','alt=\'\''),'',$this->Fields['body']); $this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']); $this->Fields['body'] = str_ireplace("<img " ,"<img alt=\"".$this->Fields['title']."\" title=\"".$this->Fields['title']."\" ",$this->Fields['body']); $this->Fields['imgurls'] = str_ireplace(array('altalt=""','alt=\'\''),'',$this->Fields['imgurls']); $this->Fields['imgurls'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['imgurls']); $this->Fields['imgurls'] = str_ireplace("<img " ,"<img alt=\"".$this->Fields['title']."\" ",$this->Fields['imgurls']);
上面是修改默認(rèn)的模板標(biāo)簽:{dede:field.body/} ,如果是其它字段,可以修改$this->Fields['body'] 為其它的字段名。
效率說明:使用了正則處理,會降低一些生成速度,如果數(shù)據(jù)量小,則可以忽略。
不修改系統(tǒng)核心文件,只用在模板里面調(diào)用就行了。把內(nèi)容頁的{dede:field.body/}調(diào)用標(biāo)簽替換為
{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 = '/(<img.*?)alt=(["\'])?.*?(?(2)\2|\s)([^>]+>)/is';
$search1 = '/(<img.*?)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}