WordPress评论调用编辑器

可能你觉得WordPress默认的评论编辑器太过单调了,有很多的修改方法可以使其增强支持更多的功能,自WordPress3.3+ 以后的版本支持了wp_editor函数,我们可以直接调用WordPress自带的编辑器,可视化或HTML,我们可以在任何地方方便的调用它。

wp_editor函数调用格式

<?php wp_editor( $content, $editor_id, $settings = array() ); ?>

其中$content的值对应评论框的内容,留空就好;$editor_id对应id="comment";其余的设置放在$settings数组中。

找到主题评论框代码

<textarea name="comment" id="comment" rows="6"></textarea>

替换为:

    <?php wp_editor( '', comment, $settings = array(
                    'quicktags'=>1,
                    'tinymce'=>0,
                    'media_buttons'=>0,
                    'textarea_rows'=>4,
                    'editor_class'=>"textareastyle"
) ); ?>

上述代码中       quicktags是HTML模式。     tinymce是可视化模式。     值1和0表示开启或关闭。     media_buttons是上传文件(只有博主在登陆后才会显示,对访客不可见)     textarea_rows是默认行数     editor_class是给WP自带的编辑器textarea区域加上自定义class即可。

展开评论