很高兴听到Sonny(wordpress3.3)有了新的编辑器APIwp_editor() 这使我们能够轻松地在自定义字段中使用编辑器的多个实例。
但我需要自定义默认编辑器(用于主要内容),但我不知道如何使用此功能。我需要为名为baner的新自定义帖子类型自定义编辑器,我需要用较少的按钮更改编辑器的大小。我知道我可以通过简单地使用自定义字段来实现,但出于某种原因,我想使用内容来描述横幅。
很高兴听到Sonny(wordpress3.3)有了新的编辑器APIwp_editor() 这使我们能够轻松地在自定义字段中使用编辑器的多个实例。
但我需要自定义默认编辑器(用于主要内容),但我不知道如何使用此功能。我需要为名为baner的新自定义帖子类型自定义编辑器,我需要用较少的按钮更改编辑器的大小。我知道我可以通过简单地使用自定义字段来实现,但出于某种原因,我想使用内容来描述横幅。
我正在寻找一种将自定义元框放置在默认编辑器上方的解决方案,我已经找到了我的老问题的解决方案(如何使用wp\\u编辑器自定义默认编辑器)!
解决方案是首先取消设置默认编辑器。然后创建另一个元盒来放置内容,然后使用wp\\u编辑器创建新的它的新实例,很简单吧?
add_action( \'add_meta_boxes\', \'page_meta_boxes\' );
public function page_meta_boxes()
{
global $_wp_post_type_features;
//ive defined my other metaboxes first with higher priority
add_meta_box(
$id = \'page_heading_meta_box\',
$title = __(\'Heading\'),
$callback = array(&$this,\'render_page_heading_metabox\'),
$post_type = \'page\',
$context = \'normal\',
$priority = \'core\'
);
add_meta_box(
$id = \'page_description_meta_box\',
$title = __(\'Description\'),
$callback = array(&$this,\'render_page_description_metabox\'),
$post_type = \'page\',
$context = \'normal\',
$priority = \'core\'
);
//check for the required post type page or post or <custom post type(here article)
if (isset($_wp_post_type_features[\'article\'][\'editor\']) && $_wp_post_type_features[\'post\'][\'editor\']) {
unset($_wp_post_type_features[\'article\'][\'editor\']);
add_meta_box(
\'wsp_content\',
__(\'Content\'),
array(&$this,\'content_editor_meta_box\'),
\'article\', \'normal\', \'core\'
);
}
if (isset($_wp_post_type_features[\'page\'][\'editor\']) && $_wp_post_type_features[\'page\'][\'editor\']) {
unset($_wp_post_type_features[\'page\'][\'editor\']);
add_meta_box(
\'wsp_content\',
__(\'Content\'),
array(&$this,\'content_editor_meta_box\'),
\'page\', \'normal\', \'low\'
);
}
}
通过这种方式,我们注册了一个名为content的新元数据库。现在是放置编辑器的时候了 function content_editor_meta_box($post)
{
$settings = array(
#media_buttons
#(boolean) (optional) Whether to display media insert/upload buttons
#Default: true
\'media_buttons\' => true,
#textarea_name
#(string) (optional) The name assigned to the generated textarea and passed parameter when the form is submitted. (may include [] to pass data as array)
#Default: $editor_id
\'textarea_name\'=>\'content\',
#textarea_rows
#(integer) (optional) The number of rows to display for the textarea
#Default: get_option(\'default_post_edit_rows\', 10)
#tabindex
#(integer) (optional) The tabindex value used for the form field
#Default: None
\'tabindex\' => \'4\'
#editor_css
#(string) (optional) Additional CSS styling applied for both visual and HTML editors buttons, needs to #include <style> tags, can use "scoped"
#Default: None
#editor_class
#(string) (optional) Any extra CSS Classes to append to the Editor textarea
#Default:
#teeny
#(boolean) (optional) Whether to output the minimal editor configuration used in PressThis
#Default: false
#dfw
#(boolean) (optional) Whether to replace the default fullscreen editor with DFW (needs specific DOM elements #and css)
#Default: false
#tinymce
#(array) (optional) Load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
#Default: true
#quicktags
#(array) (optional) Load Quicktags, can be used to pass settings directly to Quicktags using an array()
#Default: true
);
wp_editor($post->post_content,\'content\');
}
现在您可以完全自定义编辑器了!这就是现在的样子。希望它对你也有用!您可以使用设置数组中的“tinymce”键来执行此操作,如下所示:
$tinymce_options = array(
\'height\' => "300",
\'theme\' => "advanced",
\'plugins\' => "table",
// Theme options
\'theme_advanced_buttons1\' => "bold,italic,link,|,formatselect,|,bullist,numlist,outdent,indent",
\'theme_advanced_buttons2\' => "tablecontrols",
\'theme_advanced_buttons3\' => "",
\'theme_advanced_toolbar_location\' => "top",
\'theme_advanced_toolbar_align\' => "left",
\'theme_advanced_statusbar_location\' => "bottom",
\'theme_advanced_resizing\' => true,
);
$settings = array(
\'textarea_name\' => $name,
\'tinymce\' => $tinymce_options
);
wp_editor( $content , $id, $settings );
我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register