雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

dedecms

當(dāng)前位置:主頁 > CMS教程 > dedecms >

織夢(mèng)怎么讓文章中圖片自動(dòng)添加ALT屬性

來源:本站原創(chuàng)|時(shí)間:2021-08-05|欄目:dedecms|點(diǎn)擊:

打開/include/extend.func.php文件
在最下面加入:

function replaceurl($newurl)
{
global $dsql,$id;
//獲取圖片附加表imgurls字段內(nèi)容進(jìn)行處
$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
//替換圖片Alt為文檔標(biāo)題
$newurl=str_ireplace(array('alt=""','alt=/'/''),'',$newurl);
$newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img  alt=/"".$row['title']."/"",$newurl);
//去掉結(jié)尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
}
前端調(diào)用代碼:
{dede:field.body function=’replaceurl(@me)’/}
需要圖片中的style width height屬性就把上面代碼修改成下面的代碼

//文章body優(yōu)化替換
function replaceurl($newurl)
 {
global $dsql,$id;
//獲取圖片附加表imgurls字段內(nèi)容進(jìn)行處
$row = $dsql->GetOne("SELECT title FROM dede_archives where id=$id");
//去掉img的width和height
$newurl=preg_replace('/style=/"width/:(.*)/"/','',$newurl);
//替換圖片Alt為文檔標(biāo)題
$newurl=str_ireplace(array('alt=""','alt=/'/''),'',$newurl);
$newurl=preg_replace("@ [/s]{0,}alt[/s]{0,}=[/"'/s]{0,}[/s/S]{0,}[/"'/s] @isU"," ",$newurl);
$newurl=str_ireplace("<img " ,"<img  alt=/"".$row['title']."/"",$newurl);
//去掉結(jié)尾空格
$newurl=str_ireplace(" /","/",$newurl);
$newurl=str_ireplace(" />","/>",$newurl);
return $newurl;
 }

上一篇:關(guān)于DEDECMS的URL優(yōu)化的一些心得

欄    目:dedecms

下一篇:DedeCMS使用擴(kuò)展函數(shù)調(diào)用任意數(shù)據(jù)表的方法

本文標(biāo)題:織夢(mèng)怎么讓文章中圖片自動(dòng)添加ALT屬性

本文地址:http://www.jygsgssxh.com/a1/dedecms/13749.html

更多dedecms

您可能感興趣的文章

閱讀排行

本欄相關(guān)

隨機(jī)閱讀

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有