调用WordPress编辑器

WordPress1 3.4K阅读模式

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

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

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

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

wp_editor的调用函数如下:

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

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

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

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

quicktags是HTML模式。
tinymce是可视化模式。(使用可视化模式还要再进一步给可视化加上适合主题的css样式,好麻烦……)
media_buttons是上传文件(只有博主在登陆后才会显示,对访客不可见)
textarea_rows是默认行数
editor_class是给WP自带的编辑器textarea区域加上自定义class

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

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

以上,抛砖引玉而已,实际使用还需要结合主题做各种修改。

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证