如何在Wordpress元框中添加wysiwyg编辑器
我为我的自定义帖子类型创建了一个元框。有多个字段,我想使用wysiwyg编辑器而不是<textarea>
。是可以添加多个编辑器到元框?如何在Wordpress元框中添加wysiwyg编辑器
我真的很感谢你的帮忙!
非常感谢。 大傻
首先安装TinyMCE的高级插件。 第二个add “theEditor” 类,你的textarea这样
<textarea class="theEditor" name="custom_meta_box"></textarea>
完蛋了 ;)
纳比尔
http://codex.wordpress.org/Function_Reference/wp_editor是迄今为止我发现最简单的方法,因为3.3内置到WordPress的(所以升级;-))
不要忘记将'id'参数设置为与空字符串不同的东西,否则它将无法工作... – 2012-08-08 14:45:53
但您需要用nl2br()函数替换演示文稿作为textarea在自定义模板中有toogle JS问题,它将删除您的所有<P>
a nd <br/>
标签,因此所有换行符。
可以使用
add_action('edit_page_form', 'my_second_editor');
function my_second_editor() {
// get and set $content somehow...
wp_editor($content, 'mysecondeditor');
}
这为我做的伎俩用在metabox WordPress的默认文本编辑器:
http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/
它基本上是一个id创建文本区域,然后调用来自js:
tinyMCE.execCommand('mceAddControl', false, 'your_textarea_id');
希望它有帮助!
这里是全码例如:
add_action('add_meta_boxes', function() {
add_meta_box('html_myid_61_section', 'TITLEEEEE', 'my_output_function');
});
function my_output_function($post) {
wp_editor(htmlspecialchars_decode(get_post_meta($post, 'SMTH_METANAME' , true)), 'mettaabox_ID', $settings = array('textarea_name'=>'MyInputNAME'));
}
add_action('save_post', function($post_id) {
if (!empty($_POST['MyInputNAME'])) {
$datta=htmlspecialchars($_POST['MyInputNAME']);
update_post_meta($post_id, 'SMTH_METANAME', $datta);
}
});
P.S.从我的经验必备建议:
忘记添加自定义代码,使用Advanced Custom Fields,这是非常好的,并简化你的生活。
// 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>
小心解释downvote? – blockhead 2014-09-21 11:24:09