WordPress 3.3 版本开始采用新的编辑器 API,支持在任意地方使用 wp_editor 函数调用 WordPress 自带的编辑器,比如 WP 主题后台管理面板、 WP 文
章评论框等,博客吧现在要介绍的是使用 WordPress 编辑器函数 wp_editor 替代 wp 默认的文章评论框。
wp_editor 函数参数结构:
<?php wp_editor($content, $editor_id, $settings = array( 'quicktags'=>1, 'tinymce'=>0, 'media_buttons'=>0, 'textarea_rows'=>4, 'editor_class'=>"textareastyle" ) ); ?>
quicktags 是 HTML 模式。
tinymce 是可视化模式。 (使用可视化模式还要再进一步给可视化加上适合主题的 css 样式)
media_buttons 是上传文件 (对访客不可见)
textarea_rows 是默认行数
editor_class 是给 WP 自带的编辑器 textarea 区域加上自定义 class
编辑当前主题目录中的 comments.php 文件,找到评论输入框代码,如:
<textarea name="comment" id="comment" rows="6" tabindex="4"></textarea>
替换为:
<?php wp_editor( '', comment, $settings = array( 'quicktags'=> 1, //WP 默认按钮有 strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close 请自行选择 by www.weixiaoduo.com 'quicktags'=> array('buttons' => 'strong,em,link,del,img,ul,ol,li,code,spell,close',), 'tinymce'=>0, 'media_buttons'=>0, 'textarea_rows'=>4, 'editor_class'=>"textareastyle" ) ); ?>
wp_editor 中 $content 的值对应评论框的内容,留空就可以了;$editor_id 对应 id=」comment」;
保存之后,进入文章页面,评论框就会变成 WordPress 自带的编辑器了!