WP_EDITOR在前端区域不起作用

时间:2013-10-19 作者:Pietro

我正在开发一个主题,我希望有一个前端区域,但当我试图包括wp_editor() 在页面模板中,我得到以下结果:

wp_editor() problem

P、 wordpress编辑器在仪表板中运行良好。

wp editor in the dashboard works fine

彼得罗

3 个回复
SO网友:josh

您需要首先定义$settings 以及$editor_id 以及$content 变量。然后你可以打电话wp_editor().

像这样的东西应该适合你:

// default settings
$content = \'This content gets loaded first.\';
$editor_id = \'my_frontend_editor\';
$settings =   array(
    \'wpautop\' => true, // use wpautop?
    \'media_buttons\' => true, // show insert/upload button(s)
    \'textarea_name\' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
    \'textarea_rows\' => get_option(\'default_post_edit_rows\', 10), // rows="..."
    \'tabindex\' => \'\',
    \'editor_css\' => \'\', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
    \'editor_class\' => \'\', // add extra class(es) to the editor textarea
    \'teeny\' => false, // output the minimal editor config used in Press This
    \'dfw\' => false, // replace the default fullscreen with DFW (supported on the front-end in WordPress 3.4)
    \'tinymce\' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
    \'quicktags\' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
);
wp_editor( $content, $editor_id, $settings );
记住,必须先定义变量,然后才能使用它们。

SO网友:Abhik

胡猜,你在用_ (下划线)在编辑器ID中?如果是,请尝试删除它们并仅使用小写字母。。类似于thisismyeditorid.

Codex..

请注意,传递给wp\\u editor()函数的ID只能由小写字母组成。没有下划线,没有连字符。任何其他操作都会导致所见即所得编辑器出现故障。

SO网友:jake

要在模板中显示,请使用以下命令:

<?php
/*
Template Name: Template-Editor */
?>

//have to load all the scripts and header info
<?php get_header(); ?>

<?php 
$content = \'Initial content for the editor.\';
$editor_id = \'editor\';
$settings =   array(
    \'wpautop\' => true, //Whether to use wpautop for adding in paragraphs. Note that the paragraphs are added automatically when wpautop is false.
    \'media_buttons\' => true, //Whether to display media insert/upload buttons
    \'textarea_name\' => $editor_id, // The name assigned to the generated textarea and passed parameter when the form is submitted.
    \'textarea_rows\' => get_option(\'default_post_edit_rows\', 10), // The number of rows to display for the textarea
    \'tabindex\' => \'\', //The tabindex value used for the form field
    \'editor_css\' => \'\', // Additional CSS styling applied for both visual and HTML editors buttons, needs to include <style> tags, can use "scoped"
    \'editor_class\' => \'\', // Any extra CSS Classes to append to the Editor textarea
    \'teeny\' => false, // Whether to output the minimal editor configuration used in PressThis
    \'dfw\' => false, // Whether to replace the default fullscreen editor with DFW (needs specific DOM elements and CSS)
    \'tinymce\' => true, // Load TinyMCE, can be used to pass settings directly to TinyMCE using an array
    \'quicktags\' => true // Load Quicktags, can be used to pass settings directly to Quicktags using an array. Set to false to remove your editor\'s Visual and Text tabs.
    \'drag_drop_upload\' => true //Enable Drag & Drop Upload Support (since WordPress 3.9) 
);
wp_editor( $content, $editor_id, $settings );

 ?>

//have to include the footer info
<?php get_footer(); ?>
也可以使用默认设置单独显示空编辑器:

<?php

$content = \'\';
$editor_id = \'mycustomeditor\';

wp_editor( $content, $editor_id );

?>
文件:https://codex.wordpress.org/Function_Reference/wp_editor

结束

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。