'mts_ad_widget',
'description' => __('A widget for 125 x 125 ad unit (max 6 ads)', 'mythemeshop')
);
// Widget control settings
$control_ops = array (
'width' => 300,
'height' => 350,
'id_base' => 'mts_ad_widget'
);
// Create the widget
parent::__construct( 'mts_ad_widget', __('MyThemeShop: 125x125 Ads', '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'] );
$ad1 = $instance['ad1'];
$ad2 = $instance['ad2'];
$ad3 = $instance['ad3'];
$ad4 = $instance['ad4'];
$ad5 = $instance['ad5'];
$ad6 = $instance['ad6'];
$link1 = $instance['link1'];
$link2 = $instance['link2'];
$link3 = $instance['link3'];
$link4 = $instance['link4'];
$link5 = $instance['link5'];
$link6 = $instance['link6'];
$randomize = $instance['random'];
// 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;
// Randomize ads order in a new array
$ads = array();
// Display a containing div
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['ad1'] = $new_instance['ad1'];
$instance['ad2'] = $new_instance['ad2'];
$instance['ad3'] = $new_instance['ad3'];
$instance['ad4'] = $new_instance['ad4'];
$instance['ad5'] = $new_instance['ad5'];
$instance['ad6'] = $new_instance['ad6'];
$instance['link1'] = $new_instance['link1'];
$instance['link2'] = $new_instance['link2'];
$instance['link3'] = $new_instance['link3'];
$instance['link4'] = $new_instance['link4'];
$instance['link5'] = $new_instance['link5'];
$instance['link6'] = $new_instance['link6'];
$instance['random'] = $new_instance['random'];
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' => 'Our Sponsors',
'ad1' => get_template_directory_uri()."/images/125x125.gif",
'link1' => 'http://mythemeshop.com/',
'ad2' => get_template_directory_uri()."/images/125x125.gif",
'link2' => 'http://mythemeshop.com/',
'ad3' => '',
'link3' => '',
'ad4' => '',
'link4' => '',
'ad5' => '',
'link5' => '',
'ad6' => '',
'link6' => '',
'random' => false
);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>