Discuz 3.4门户文章页插入图片,图片自动添加alt属性
摘要: 沭阳web经常使用discuz门户功能来制作网站,其中不得不说Discuz 的功能还是非常强大的,但在使用过程中发现在发表文章时添加了图片却不能像其他CMS程序这样自动添加 alt 标签,经过一番研究,初步解决了这个问题,目 ...
Discuz 3.4门户文章页插入图片,图片自动添加alt属性。
沭阳web经常使用discuz门户功能来制作网站,其中不得不说Discuz 的功能还是非常强大的,但在使用过程中发现在发表文章时添加了图片却不能像其他CMS程序这样自动添加 alt 标签,经过一番研究,初步解决了这个问题,目前还没有Bug,等待长时间验证,方法如下:
在实施本方法之前请先备份网站数据,以防不测;这次修改需要修改两个文件,分别是:
static/image/editor/editor_function.js
template/default/home/spacecp_blog.htm
一、增加一个文件
static/image/editor/editor_function.js 复制一份,重命名为:bgeditor_function.js
二、修改:editor_function.js
查找代码:
二、修改:editor_function.js
查找代码:
function insertImage(image, url, width, height) {
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);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改为:
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="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
三、修改刚刚建立的bgeditor_function.js
同样查找代码:
同样查找代码:
function insertImage(image, url, width, height) {
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);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改为:
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="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
四、编辑:template/default/home/spacecp_blog.htm
查找:editor_function.js,替换为:bgeditor_function.js
编辑完毕保存,把文件上传到原来位置,增加的bgeditor_function.js与editor_function.js一块放在同一目录。后台发布一片文章,输入文章标题,上传图片,进入源代码模式,看看图片是不是有了 alt 标签?!
查找:editor_function.js,替换为:bgeditor_function.js
编辑完毕保存,把文件上传到原来位置,增加的bgeditor_function.js与editor_function.js一块放在同一目录。后台发布一片文章,输入文章标题,上传图片,进入源代码模式,看看图片是不是有了 alt 标签?!
特别提醒:
按本教程修改后,老文章需要重新编辑文章,图片重新插入到文章中,图片ALT属性才会有。如果不编辑,老旧文章图片是没有ALT属性的。