【实测】Discuz门户文章插入图片自动添加 alt 标签-Discuz教程下载

【实测】Discuz门户文章插入图片自动添加 alt 标签

开通本站Svip会员,全站资源免费下
最近用 Discuz 搭建了个网站——源码www.tuyuanma.com),用到了门户功能,不得不说Discuz 的功能还是非常强大的,但在使用过程中发现在发表文章时添加了图片却不能像 WordPress 这样自动添加 alt TAG.html" target="_blank" class="relatedlink">标签,经过一番研究,初步解决了这个问题,目前还没有 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

查找代码:
  1. function insertImage(image, url, width, height) {
  2.     url = typeof url == 'undefined' || url === null ? image : url;
  3.     width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
  4.     height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
  5.     var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
  6.     edit_insert(html);
  7. }
复制代码
修改为:
  1. function insertImage(image, url, width, height, subject) {
  2.     url = typeof url == 'undefined' || url === null ? image : url;
  3.     width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
  4.     height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
  5.     subject = $('title').value;
  6.     var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
  7.     edit_insert(html);
  8. }
复制代码
再修改刚刚建立的bgeditor_function.js

同样查找代码:
  1. function insertImage(image, url, width, height) {
  2.     url = typeof url == 'undefined' || url === null ? image : url;
  3.     width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
  4.     height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
  5.     var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
  6.     edit_insert(html);
  7. }
复制代码
修改为:
  1. function insertImage(image, url, width, height, subject) {
  2.     url = typeof url == 'undefined' || url === null ? image : url;
  3.     width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
  4.     height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
  5.     var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
  6.     edit_insert(html);
  7. }
复制代码
再编辑:template/default/home/spacecp_blog.htm

查找:editor_function.js

替换为:bgeditor_function.js

编辑完毕保存,把文件上传到原来位置,增加的bgeditor_function.js与editor_function.js一块放在同一目录。后台发布一片文章,输入文章标题,上传图片,进入源代码模式,看看图片是不是有了 alt 标签?!

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部