'mts_ad_300_widget', 'description' => __('A widget for 300 x 250 ad (Single banner)', 'mythemeshop') ); // Widget control settings $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'mts_ad_300_widget' ); // Create the widget parent::__construct( 'mts_ad_300_widget', __('MyThemeShop: 300x250 Ad', 'mythemeshop'), $widget_ops, $control_ops ); } /*-----------------------------------------------------------------------------------*/ /* Display Widget /*-----------------------------------------------------------------------------------*/ function widget( $args, $instance ) { extract( $args ); // Variables from the widget settings $title = apply_filters('widget_title', $instance['title'] ); $ad = $instance['ad']; $link = $instance['link']; // Before widget (defined by theme functions file) echo $before_widget; // Display the widget title if one was input if ( $title ) echo $before_title . $title . $after_title; // Display a containing div echo '
'; // Display Ad if ( $link ) echo ''; elseif ( $ad ) echo ''; echo '
'; // After widget (defined by theme functions file) echo $after_widget; } /*-----------------------------------------------------------------------------------*/ /* Update Widget /*-----------------------------------------------------------------------------------*/ function update( $new_instance, $old_instance ) { $instance = $old_instance; // Strip tags to remove HTML (important for text inputs) $instance['title'] = strip_tags( $new_instance['title'] ); // No need to strip tags $instance['ad'] = $new_instance['ad']; $instance['link'] = $new_instance['link']; return $instance; } /*-----------------------------------------------------------------------------------*/ /* Widget Settings (Displays the widget settings controls on the widget panel) /*-----------------------------------------------------------------------------------*/ function form( $instance ) { // Set up some default widget settings $defaults = array( 'title' => '', 'ad' => get_template_directory_uri()."/images/300x250.gif", 'link' => 'http://mythemeshop.com/', ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>