【问题标题】:Replacing a plugin created textarea by WP editor替换由 WP 编辑器创建的插件 textarea
【发布时间】:2016-09-28 07:47:29
【问题描述】:

需要你们的帮助。我有一个页面,通过 Private Content 插件我创建了一个简单的 textarea 字段。我需要做的是通过添加富文本编辑器来改进该文本区域,我认为标准的 WP 应该没问题。

您能否直接说明我需要过去哪些代码以及我应该在哪里执行?如您所见,编码不是我的强项。尝试谷歌并在这里搜索,有一些结果,但还不够清楚,我无法正确实施。

希望得到您的帮助!

【问题讨论】:

    标签: wordpress textarea wp-editor


    【解决方案1】:

    使用函数

    wp_editor( $content, $editor_id, $settings = array() );
    

    您可以显示默认的 wordpress 编辑器。快速(未消毒)示例:

    你的表单内容(别忘了加上<form>标签):

    <?php wp_editor( 'I am a prefilled sample text', 'editorname' ?>
    

    从中读取的脚本:

    $editor_content = $_POST['editorname']
    //do stuff, perhaps put to database
    save_to_db( $editor_content ) //for example
    

    需要注意的一些快速事项

    • 编辑器被渲染也就是直接回显,所以你不必添加echo
    • $editor_id 只能包含小写字母。没有下划线。

    但你自己看看这里:https://codex.wordpress.org/Function_Reference/wp_editor

    【讨论】:

      【解决方案2】:

      使用此代码:

      wp_editor($content, 'content_id', array('textarea_name' => 'content_id', 'editor_class'=>'requiredField', 'textarea_rows'=>'6', 'media_buttons' => true ,'tinymce ' => 真) );

      【讨论】:

      • 用上面的代码替换文本区域 html 并放在上面这段代码$content = get_post_meta($_GET['post'], 'post_meta _name', true);
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多