defaults = array( 'title' => '', 'items_number' => 1, 'layout' => 'one-column', 'enable_hide_404' => 1, ); $widget_ops = array( 'classname' => 'ct-advertisement-image ctadvertisement', 'description' => __( 'Use this widget to add Image as Advertisement', 'automobile' ), ); $control_ops = array( 'id_base' => 'ct-advertisement-image', ); parent::__construct( 'ct-advertisement-image', // Base ID __( 'CT: Advertisement Images', 'automobile' ), // Name $widget_ops, $control_ops ); } /** * Creates the form for the widget in the back-end which includes the Title , adcode, image, alt * $instance Current settings */ function form($instance) { //* Merge with defaults $instance = wp_parse_args( (array) $instance, $this->defaults ); ?>


id="get_field_id( 'target' . '_' . $i ); ?>" name="get_field_name( 'target' . '_' . $i ); ?>" />

id="get_field_id('enable_hide_404'); ?>" name="get_field_name('enable_hide_404'); ?>" />

defaults ); if ( $instance['enable_hide_404'] && is_404() ) { //Bail Early if the page is 404 error page and the widget is set to be hidden in that page return; } echo $args['before_widget']; // Set up the author bio if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } echo '
'; for( $i=1; $i<= absint( $instance['items_number'] ); $i++ ) { $image = isset( $instance['image' . '_' . $i] ) ? $instance['image' . '_' . $i] : ''; $image_link = isset( $instance['image_link' . '_' . $i] ) ? $instance['image_link' . '_' . $i] : ''; $target = isset( $instance['target' . '_' . $i] ) ? $instance['target' . '_' . $i] : ''; $alt = isset( $instance['alt' . '_' . $i] ) ? $instance['alt' . '_' . $i] : ''; $base = '_self'; if ( $target ) { $base = '_blank'; } if ( '' != $image ) { echo '
'; $image_output = '' . esc_attr( $alt ) . ''; if( '' != $image_link ) { echo ' ' . $image_output . ' '; } else { echo $image_output; } echo '
'; } } echo '
'; echo $args['after_widget']; } } //From Codex: https://codex.wordpress.org/Widgets_API add_action('widgets_init', create_function('', 'return register_widget("automobile_advertisement_image_widget");') );