Discuz 3.X 门户文章插入图片自动添加 alt 标签
2016-11-03 12:04
399 查看
最近用 Discuz 搭建了个网站——儿童安全座椅网(www.bbseat.com.cn),用到了门户功能,不得不说Discuz 的功能还是非常强大的,但在使用过程中发现在发表文章时添加了图片却不能像 WordPress 这样自动添加 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
查找代码:
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); 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 标签?!
相关文章推荐
- discuz 论坛门户发布文章带alt属性标签的方法,转载自老申随笔记网,希望对各位有所帮助.SEO优化之图片alt标签的声明.
- DedeCMS文章里图片ALT注释自动填充为文章标题
- Discuz!门户列表页,文章中无图片时,随机选择一张作为封面
- discuz! X3 门户文章添加字段
- 织梦网站巧用标签实现图片自动Alt功能,强化织梦seo效果
- WordPress纯代码实现自动为文章添加标签及标签内链接
- discuz!帖中图片附件添加alt描述的快捷方法
- Discuz! X2.0/X2.5图片自动添加ALT标签,让你的网站收录狂飞
- DedeCMS文章里图片ALT注释自动填充为文章标题
- 使用php自动将文章标题或内容进行分词,添加和删除标签功能实例!
- Discuz!教程之门户列表页文章中无图片时,从图库中选择一张作为封面
- html图片标签为什么要添加alt属性?
- Discuz 门户列表页自动获取内容图片
- 织梦网站巧用标签实现图片自动Alt功能,强化织梦seo效果
- 网易新闻首页的实现,可以添加,移除标签,自动滚动图片,无限左右切换图片
- discuz自动添加兼容html5标签的音乐播放器
- 去掉CSDN使用MarkDown编辑器插入图片自动添加的水印
- img图片标签赋予alt属性是否需要
- SmartForms中系统自动插入的排序事件如何添加Program lines.
- Java 记事本——今天添加了简单的插入时间和自动换行菜单的实现