我创建了一个自定义帖子类型,并找到了一个很好的代码,可以添加所见即所得编辑器。我完全可以让这个编辑器显示在我的帖子类型后端。但我不知道如何添加另一个编辑器,如何在同一个单曲中显示第二个编辑器的内容。php文件,我将在其中显示第一个文件的内容。让我先写下代码:
下面是添加所见即所得编辑器(functions.php)的实现代码:
define(\'WYSIWYG_META_BOX_ID\', \'my-editor\');
define(\'WYSIWYG_EDITOR_ID\', \'myeditor\'); //Important for CSS that this is different
define(\'WYSIWYG_META_KEY\', \'extra-content\');
add_action(\'admin_init\', \'wysiwyg_register_meta_box\');
function wysiwyg_register_meta_box(){
add_meta_box(WYSIWYG_META_BOX_ID, __(\'Display title\', \'wysiwyg\'), \'wysiwyg_render_meta_box\', \'artists\');
}
function wysiwyg_render_meta_box(){
global $post;
$meta_box_id = WYSIWYG_META_BOX_ID;
$editor_id = WYSIWYG_EDITOR_ID;
//Add CSS & jQuery goodness to make this work like the original WYSIWYG
echo "
<style type=\'text/css\'>
#$meta_box_id #edButtonHTML, #$meta_box_id #edButtonPreview {background-color: #F1F1F1; border-color: #DFDFDF #DFDFDF #CCC; color: #999;}
#$editor_id{width:100%;}
#$meta_box_id #editorcontainer{background:#fff !important;}
#$meta_box_id #$editor_id_fullscreen{display:none;}
</style>
<script type=\'text/javascript\'>
jQuery(function($){
$(\'#$meta_box_id #editor-toolbar > a\').click(function(){
$(\'#$meta_box_id #editor-toolbar > a\').removeClass(\'active\');
$(this).addClass(\'active\');
});
if($(\'#$meta_box_id #edButtonPreview\').hasClass(\'active\')){
$(\'#$meta_box_id #ed_toolbar\').hide();
}
$(\'#$meta_box_id #edButtonPreview\').click(function(){
$(\'#$meta_box_id #ed_toolbar\').hide();
});
$(\'#$meta_box_id #edButtonHTML\').click(function(){
$(\'#$meta_box_id #ed_toolbar\').show();
});
//Tell the uploader to insert content into the correct WYSIWYG editor
$(\'#media-buttons a\').bind(\'click\', function(){
var customEditor = $(this).parents(\'#$meta_box_id\');
if(customEditor.length > 0){
edCanvas = document.getElementById(\'$editor_id\');
}
else{
edCanvas = document.getElementById(\'content\');
}
});
});
</script>
";
//Create The Editor
$content = get_post_meta($post->ID, WYSIWYG_META_KEY, true);
the_editor($content, $editor_id);
//Clear The Room!
echo "<div style=\'clear:both; display:block;\'></div>";
}
add_action(\'save_post\', \'wysiwyg_save_meta\');
function wysiwyg_save_meta(){
$editor_id = WYSIWYG_EDITOR_ID;
$meta_key = WYSIWYG_META_KEY;
if(isset($_REQUEST[$editor_id]))
update_post_meta($_REQUEST[\'post_ID\'], WYSIWYG_META_KEY, $_REQUEST[$editor_id]);
}
下面是显示内容的显示代码(单cpt.php):<?php $content = get_post_meta($post->ID, WYSIWYG_META_KEY, true); ?>
<p><?php echo $content; ?></p>
My problem: 在显示代码中,我们有一个常量“WSIWYG\\u META\\u KEY”。所以这意味着我不能在同一个单曲中再次使用此代码。php文件,以便显示我将在函数中实现的另一个编辑器的另一个内容。php。你们有没有人看到一个解决方案,允许我添加两个编辑器,并在我的单张中分别显示这两个编辑器的内容。php文件?