黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

WordPress更新到3.3了,增加了很多新特性。由于采用新的编辑器API,导致原来HTML编辑模式所有quicktags自定义按钮全灭……好嘛,查资料发现这些更改应该是为了新函数wp_editor

WordPress 3.3新增加的一个功能是可以在任意地方调用WP自带的编辑器,唔,换句话说就是可以将评论输入框改为WP自带的编辑器。是不是方便了很多?顺带来折腾一下。

首先来看看一般WP主题评论框代码:

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

wp_editor的调用函数如下:

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

wp_editor中$content的值对应评论框的内容,留空就好;$editor_id对应id="comment";其余的设置放在$settings数组中。详细的设置使用请参看官方Codex

使用wp_editor函数来代替评论输入框,这里给出我自己使用的。1、0表示开启或关闭。

1
2
3
4
5
6
7
<?php wp_editor( '', comment, $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

全部开启如下图

补充,如果想自定义按钮标签:

1
2
3
4
5
6
7
8
9
<?php wp_editor( '', comment, $settings = array(
        'quicktags'=> 1,
        //WP默认按钮有strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close 请自行选择
        '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"
) ); ?>

posted on 2012-02-15 16:53  黄聪  阅读(2896)  评论(0编辑  收藏  举报