用DedeCMS在做圖片站,一般都是采集,很多圖片沒有alt標簽,對搜索引擎來說并不友好,一張一張寫相當麻煩,可以修改為文檔關鍵字或文章標題作為圖片alt描述。圖片的匹配度當然沒有手動的好,但做站群的時候能省事就好。
修改文件include/arc.archives.class.php
找到
//設置全局環境變量
$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');
在下面增加代碼
查看源碼打印代碼幫助
//替換圖片Alt為文檔關鍵字+標題
$this->Fields['body'] = str_ireplace(array('alt=""','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['keywords']." . ".$this->Fields['title']."' ",$this->Fields['body']);
//end
重新生成文章即可,如果是其它字段,可以修改$this->Fields['body'] 為其它的字段名。