我试图在Wordpress中为我的小部件使用内置的富文本(wp\\u editor())编辑器,但我似乎找不到任何简单的方法来使用它。。
我知道你可以用它Black Studio TinyMCE 我能做到,但怎么做?
My form function
function form($instance)
{
$instance = wp_parse_args((array) $instance, array( \'box1\' => \'\', \'box2\' => \'\', \'box3\' => \'\', \'box4\' => \'\' ));
$box1 = $instance[\'box1\'];
$box2 = $instance[\'box2\'];
$box3 = $instance[\'box3\'];
$box4 = $instance[\'box4\'];
$boxqty = $instance[\'boxqty\'];
?>
<p><label for="<?php echo $this->get_field_id(\'boxqty\'); ?>">Number of blocks: (1-4) <input class="widefat" id="<?php echo $this->get_field_id(\'boxqty\'); ?>" name="<?php echo $this->get_field_name(\'boxqty\'); ?>" type="text" value="<?php echo attribute_escape($boxqty); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id(\'box1\'); ?>">Box 1:
<textarea class="widefat mceEditor" id="<?php echo $this->get_field_id(\'box1\'); ?>" name="<?php echo $this->get_field_name(\'box1\'); ?>"> <?php echo $box1; ?></textarea>
</label></p>
<p><label for="<?php echo $this->get_field_id(\'box2\'); ?>">Box 2:
<textarea class="widefat" id="<?php echo $this->get_field_id(\'box2\'); ?>" name="<?php echo $this->get_field_name(\'box2\'); ?>"><?php echo $box2; ?></textarea>
</p>
<p><label for="<?php echo $this->get_field_id(\'box3\'); ?>">Box 3:
<textarea class="widefat" id="<?php echo $this->get_field_id(\'box3\'); ?>" name="<?php echo $this->get_field_name(\'box3\'); ?>"><?php echo $box3; ?></textarea>
</p>
<p><label for="<?php echo $this->get_field_id(\'box4\'); ?>">Box 4:
<textarea class="widefat" id="<?php echo $this->get_field_id(\'box4\'); ?>" name="<?php echo $this->get_field_name(\'box4\'); ?>"><?php echo $box4; ?> </textarea>
</p>
<?php
wp_editor(\'Test text\', \'test-editor\');
}
SO网友:ItsGeorge
不久前,我偶然发现了这个解决方案;这可能就是您正在寻找的:
我将此添加到我的主题功能中。php文件。。。
// First, I created a shortcode for a function, that would typically be inserted in to a template file, so that it could be inserted in to a widget.
add_shortcode(\'myshortcode\', \'myfunction\');
function myfunction() {
if ( function_exists( \'get_smooth_slider_category\' ) ) { get_smooth_slider_category(\'featured\'); }
}
// Then you can add this to allow shortcodes to be used in widgets.
/* Make shortcodes work in widgets */
add_filter(\'widget_text\', \'do_shortcode\');
然后我又加了一句
[myshortcode]
文本控件和中提琴;我在小部件中有一个函数。