• 黄聪:自定义插件的时候,如何调用WordPress编辑器(wp_editor)转


    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"
    ) ); ?>

  • 相关阅读:
    LeetCode 79. 单词搜索(Word Search)
    LeetCode 39. 组合总和(Combination Sum)
    LeetCode 34. 搜索范围(search for a range)
    LeetCode 300. 最长上升子序列(Longest Increasing Subsequence)
    一段程序的分析——C++析构器,何时析构
    C++ 字符串, 数字 相互转化
    MFC 如何为控件关联变量
    上位机驱动开发经验之修改3个“附加”
    MFC Edit控件的使用~~
    thinkphp中AJAX返回ajaxReturn()方法分析
  • 原文地址:https://www.cnblogs.com/huangcong/p/2352896.html
Copyright © 2020-2023  润新知