discuz 門户添加圖片時,為了 SEO 的需要,我們要手工的給圖片添加 ALT 信息,如果文章中的圖片多的話,這樣操作就比較麻煩了。其實在學做網站過程中,可以通過修改一些代碼來讓程序自動添加文章圖片自動加 Alt 信息。
要實現這種自動添加 ALT 信息的功能,需要修改文件:static/image/editor/editor_function.js 。
第一步:首先複製 editor_function.js,重命名為 bgeditor_function.js

第二步:打開 editor_function.js 進行編輯,在裏面查找以下的代碼開頭的一段代碼:
function insertImage(image, url, width, heigh) {

將這段代碼替換成以下的代碼:
function insertImage(image, url, width, height,subject) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
subject = $('title').value;
var html = '<p><a href="'%20+%20url%20+%20'" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
第三步:打開 bgeditor_function.js 進行編輯,通過 CTRL+F 查找以下的代碼:
function insertImage(image, url, width, heigh) {
將這段代碼替換成以下的代碼:
<blockquote><blockquote>function insertImage(image, url, width, height,subject) {</blockquote></blockquote>
第四步:再編輯:template/default/home/spacecp_blog.htm,查找以下的代碼:
editor_function.js
將它替換成以下的代碼:
bgeditor_function.js
第五步:在自己的門户網站下發布一篇帶有圖片的文章,發佈後查看網頁源代碼,圖片就自動添加了文章標題為圖片的 ALT 信息。