織夢(mèng)文檔后臺(tái)添加圖片默認(rèn)alt=""為空,如果你想給所有的文檔內(nèi)容里的img alt="" title="" 補(bǔ)上標(biāo)題,方法有2種!
方法一
打開(kāi)Include/ arc.archives.class.php
查找:大概240行
@SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
在上面代碼后面添加:
//替換圖片Alt和title為文檔標(biāo)題xinzeng $this->Fields['body'] = str_ireplace(array('altalt=""','alt='''),'',$this->Fields['body']);$this->Fields['body'] = preg_replace("@ [s]{0,}alt[s]{0,}=["'s]{0,}[sS]{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,}[sS]{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’] 為其它的字段名。
效率說(shuō)明:使用了正則處理,會(huì)降低一些生成速度,如果數(shù)據(jù)量小,則可以忽略。
方法二
不修改系統(tǒng)核心文件,只用在模板里面調(diào)用就行了。
把文章內(nèi)容頁(yè)文章內(nèi)容標(biāo)簽
{dede:field.body/}改成
{dede:field.body runphp=yes}global $dsql,$id,$aid;$myid = isset($id) ? $id : $aid;$row = $dsql->GetOne("SELECT title FROM `dede_archives` WHERE id=$myid");$title = $row['title'];$str = @me;$search = '/(<img.*?)alt=(["'])?.*?(?(2)|s)([^>]+>)/is';$search1 = '/(<img.*?)title=(["'])?.*?(?(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}
改好后,生成文檔內(nèi)容頁(yè),查看源代碼,效果如下