POST TIME:2019-09-30 11:22
對seo有一點鏈接的人知道 搜索引擎的蜘蛛是無法識別圖片的,它主要是根據alt標簽來識別這張圖片是什么意思,我們可以看到當我們在百度圖片或者是谷歌圖片中搜索相關內容的時候,顯示出來的圖片基本上都市帶有alt標簽的,并且alt標簽中的內容噎死我們搜索的內容,這就應正了這一點。
但是織夢cms并沒有為每一張圖片添加alt標簽,這就需要我們自己解決了。
1、文章中添加alt標簽
我們打開:
Include/ arc.archives.class.php
查找到一下代碼:
//設置全局環境變量 $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename']; @SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives');
在其之后添加:
$this->Fields['body'] = str_ireplace(array('','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 ",$this->Fields['body']);這樣我們就可以為文章的每張圖片都加上alt標簽了,標簽的內容就是文章的標題。
2、為圖集中的圖片添加alt標簽
在上面的基礎上 我們再添加
$this->Fields['imgurls'] = str_ireplace(array('','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 ",$this->Fields['imgurls']);這三行代碼 就可以為圖集中的圖片加上alt標簽了!