原文標題:「織夢文章內容圖片加alt和title」這麼做有利用SEO優化
織夢文檔後台添加圖片默認alt=""為空,如果你想給所有的文檔內容裏的img alt="" title="" 補上標題,我們不需要去改程序文件,直接在標簽裏runphp一下
首先我們找到織夢文章內容頁的模板,在文章內容頁找到內容標簽
{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}
文章來源:織夢仿站開發教程
本文來源:/website/322.html