最近用 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 3.X 门户文章插入图片自动添加 alt 标签的更多相关文章

  1. word 2013 题注、图注、插入图片自动修改大小、批量更新题注编号

    1 .题注 图片下面的文字说明,如  图 1.1.1 2.图注 图的标题格式,可以右键修改段落为居中,选中图片,点下此格式快捷居中等其他格式 3. 题注插入 效果 如下 4.题注自动居中对齐 先点击图 ...

  2. WordPress发布文章/页面时自动添加默认的自定义字段

    如果你每篇文章或页面都需要插入同一个自定义字段和值,可以考虑在WordPress发布文章/页面时,自动添加默认的自定义字段.将下面的代码添加到当前主题的 functions.php 即可: 1 2 3 ...

  3. php正则给图片提取/替换/添加alt标签的正则代码

    有的时候我们需要对富文本编辑器的内容做一些处理,例如图片的alt标签.百度的富文本编辑器添加的图片就是没有的,那么我们要添加就必须使用正则了,下面一起来看看如何实现吧. $preg = "/ ...

  4. UEditor使用有感(红色),保存内容时,会自动添加p标签

    UEditor 介绍 UEditor 是由百度「FEX前端研发团队」开发的所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码. 1 入门部署 ...

  5. 蚂蚁分类信息商家发布文章、商品外链及远程图片自动添加nofollow属性

    蚂蚁商户发布文章.商品是可以添加外链或者直接用外部图片,但是这对分类网站运营不利. 所以要对外链进行过滤,演示网站保洁,蚂蚁分类的源码. 下面就说下怎么处理自动给外链自动加上nofollow属性. 1 ...

  6. Discuz! 3.3全站帖子自动添加图片alt标签

    网站想要更好的适应搜索引擎的话,就要把最基础的一些小优化标签做好, 虽然说现在搜索都很厉害能够识别图片,但是除非的你的图片每一张都是周杰伦.范冰冰等知名图片... 不然你还是要给你自己的图添加alt标 ...

  7. 如何修改 Discuz 门户文章页默认视频大小

    在 Discuz 系统中,论坛插入 Flash 等可以输入自定义的尺寸,但是门户文章页不可以修改.经过一番研究,找到了修改门户文章页默认视频大小的方法如下,希望对你有用:找到:/source/func ...

  8. discuz X3.1的门户文章实现伪静态,利于搜索引擎收录url的地址修改

    最近在捣鼓DZ框架,这两天发现文章的收录情况并不是太理想,做了很多优化方面的工作,今天主要解决了DZ门户的文章链接伪静态化,在这次修改之前,也做过一次在网上找的静态化修改,之前做的方式是: 1.在DZ ...

  9. dedecms复制网上的带有图片的文章,图片不能自动下载到本地的解决方法

    dede有时看到比较好的文章需要复制,粘贴到自己的dede后台发布,dede是有图片自动本地化的功能,就是复制过来后自动下载到你的服务器上了,这样省去了你单独去另存图片再上传的过程,尤其是遇到有很多图 ...

随机推荐

  1. 采用handle消息机制实现轮播效果

    // 自动轮播条显示 if (mhandle == null) { mhandle = new Handler() { public void handleMessage(Message mes) { ...

  2. dispatch_group_async可以实现监听一组任务是否完成,完成后得到通知执行其他的操作。这个方法很有用,比如你执行三个下载任务,当三个任务都下载完成后你才通知界面说完成的了

    dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ); dispatch_group_ ...

  3. [Arduino] 外部中断

    原文:http://www.arduino.cn/thread-2421-1-1.html 1.什么是中断? 试想一下,你正在家里吃饭,这时传来了敲门声,虽然你巨饿,虽然面前全是山珍海味,但此时你不得 ...

  4. arcgis gdb含下划线_和%的查询 by gisoracle

    XMMC LIKE '%\_%' ESCAPE '\'              by gisoracle 2015.1.25 XMMC LIKE  '%\%%' escape '\'         ...

  5. ArcGis学习教程免费版在线观看

    ArcGis学习教程免费版在线观看 作者:池建    文章来源:清华大学出版社    点击数:150220    更新时间:2013-8-8 摘要:Arcgis学习视频教程根据书籍章节逐步讲解较为详细 ...

  6. html 中根据后台参数显示 相应的样式 EL表达式

    <li><a class="${return_product_statu==-1||return_product_statu==null?'switch_xz':'none ...

  7. js中Math()函数&&数据类型转换

    Math()函数: x的y次方:Math.pow(x,y) 取小数点后两位:num.toFixed(2) 数据类型转换: 字符串转换为数字:parseInt(num)转换为整数:parseFloat( ...

  8. 正则转nfa:完成

    太累了,感觉不会再爱了.问题已经解决,具体的懒得说了. #include "regular_preprocess.h" //这个版本终于要上nfa了,好兴奋啊 //由于连个节点之间 ...

  9. CENTOS如何禁用ROOT本地或远程SSH登录

    下面详细描述如何禁止root登录. 禁止root本地登录 禁止root远程ssh登录 禁止root本地登录 修改/etc/pam.d/login文件增加下面一行   1 auth required p ...

  10. Javascript -- toFixed()函数

    Javascript——toFiexed()函数 1. toFixed(n) 限制小数点后位数,四舍五入.n:0~20 . 2. 作用对象必须是number,不能为其他类型.如(8.001).toFi ...