帝國CMS 釋出資訊時自動把內容中的圖片alt和title屬性替換為資訊標題
阿新 • • 發佈:2019-02-09
1.把下面的程式碼放到/e/class/userfun.php (放到最後?>的前面)
function user_imgalt($mid,$f,$isadd,$isq,$value,$cs){ $title=$_POST['title']; $htmls=$value; $pattern = "/<img[^>]+>/"; preg_match_all($pattern, $htmls, $matches); for ($i=0; $i<=count($matches[0]); $i++) { preg_match_all("/alt=\".+?\"/",$matches[0][$i],$altimg); preg_match_all("/title=\".+?\"/",$matches[0][$i],$titleimg); $t_alt=count($altimg[0]); if($t_alt==0){ $htmls=str_replace("<img","<img alt=\"{$title}\"",$htmls); $htmls=str_replace("<img","<img title=\"{$title}\"",$htmls); } } return $htmls; }
2.在模型里正文欄位一般是newstext(也可以是其它欄位),在欄位處理函式文字框填上user_imgalt 如下圖:
3.釋出資訊的時候就可以自動替換圖片alt和title屬性為資訊標題了!