第一期:
我的客户想为他们的wordpress站点定制一个HTML渲染侧边栏小部件。我创建了一个简单的,允许他们选择颜色(类切换),并给他们一个文本区,把他们的HTML。现在他们已经要求一个基本的所见即所得的接口附加到它(CKEditor或TinyMCE),但我不知道如何将其添加到小部件代码内的文本区。有人知道如何,有一个例子,或者一个地方看看它是如何工作的吗?谢谢!
EDIT(使用wp_editor后):
所以我有我的代码到这一点,但编辑器被禁用,无法使用。知道为什么吗?
<fieldset>
<label>Enter your HTML</label>
<?php
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'tinymce' => array(
'theme_advanced_buttons1' => ',bold,italic,underline,|,link,unlink',
),
'quicktags' => false
);
$bodyID = $this->get_field_id('body');
$content = '';
wp_editor($content, $bodyID, $settings );
?>
</fieldset>
使用wp_editor
函数,您的代码将看起来像这样:
http://codex.wordpress.org/Function_Reference/wp_editor
<fieldset>
<label> Your label for the text area </label>
<?php
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'tinymce' => array(
'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' .
'bullist,blockquote,|,justifyleft,justifycenter' .
',justifyright,justifyfull,|,link,unlink,|' .
',spellchecker,wp_fullscreen,wp_adv ',
),
'quicktags' => false
);
wp_editor('initial content', 'id of textarea', $settings );
?>
</fieldset>
注意如果你想把内容放在前端的WP数据库中,你应该使用另外的wp_insert_post
函数和一个POST
变量作为链接