add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
// get and set $content somehow...
wp_editor( $content, 'mysecondeditor' );
}
3
// for custom post type
function wo_second_editor($post) {
echo "<h3>Write here your text for the blue box on the right:</h3>";
$content = get_post_meta($post->ID, 'wo_blue_box' , true ) ;
wp_editor( htmlspecialchars_decode($content), 'wo_blue_box', array("media_buttons" => false) );
}
add_action('edit_form_advanced', 'wo_second_editor');
function wo_save_postdata($post_id, $post, $update) {
//...
if (!empty($_POST['wo_blue_box'])) {
$data=htmlspecialchars($_POST['wo_blue_box']);
update_post_meta($post_id, 'wo_blue_box', $data );
}
}
add_action('save_post', 'wo_save_postdata');
// Theme:
<div class="blue">
<?php
$content = get_post_meta(get_the_ID(), 'wo_blue_box' , true );
$content = htmlspecialchars_decode($content);
$content = wpautop( $content );
echo $content;
?>
</div>
8 回答
这是完整的代码示例:
P.S.必须 - 根据我的经验推荐:
忘记添加自定义代码,使用 Advanced Custom Fields ,它非常好并简化您的生活 .
到目前为止,http://codex.wordpress.org/Function_Reference/wp_editor是我发现的最简单的方法,自3.3版以来内置于Wordpress中(因此升级;-))
但是您需要使用nl2br()函数替换演示文稿,因为自定义模板中的textarea具有toogle JS问题,这会删除所有
<P>
和
标记,从而删除所有换行符 .您可以使用metabox中的wordpress默认文本编辑器
试试自定义字段模板插件http://wordpress.org/extend/plugins/custom-field-template/
首先安装TinyMCE Advanced插件 . 其次,将“theEditor”类添加到您的textarea中
而已 ;)
纳比勒
这对我有用:
http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/
它基本上用id创建你的textarea,然后从js调用:
希望能帮助到你!