我想为我的小部件创建一个简码。
这是我创建小部件的代码,如果我想为这个小部件创建短代码,我该怎么做?
<pre>
function my_slider_post() {
register_widget('my_slider_post');
}
add_action('widgets_init','my_slider_post');
class my_slider_post extends WP_Widget {
function my_slider_post() {
$widget_ops = array('classname' => 'my_slider_post','description' => __('Widget display Slider Post','theme'));
add_action('admin_enqueue_scripts', array($this, 'scripts'));
parent::__construct('mysliderpost',__('my Slider Post','theme'),$widget_ops);
}
function widget( $args, $instance ) {
extract( $args );
/* User-selected settings. */
$title = apply_filters('widget_title', $instance['title'] );
$img1 = $instance['image_one'];
$title1 = $instance['title_one'];
$desc1 = $instance['desc_one'];
$img2 = $instance['image_two'];
$img3 = $instance['image_three'];
/* Before widget (defined by themes). */
echo $before_widget;
/* Title of widget (before and after defined by themes). */
if ( $title )
echo $before_title . $title . $after_title;
<!-- start -->
// code html to show
/* After widget (defined by themes). */
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags (if needed) and update the widget settings. */
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['image_one'] = $new_instance['image_one'];
$instance['title_one'] = $new_instance['title_one'];
$instance['desc_one'] = $new_instance['desc_one'];
$instance['image_two'] = $new_instance['image_two'];
$instance['image_three'] = $new_instance['image_three'];
return $instance;
}
public function scripts()
{
wp_enqueue_script( 'media-upload' );
wp_enqueue_media();
wp_enqueue_script('our_admin', get_template_directory_uri() . '/js/our_admin.js', array('jquery'));
}
public function form( $instance ) {
// code html to show on widget into sidebar control panel
}
}
</pre>