wordpress - How can widget show image -


i writing widget showing image via input local path of image. stuck @ phase of showing image. probably, problem exists in function: widget. tried many ways, (you can see code in widget function), still not working. 1 point me error?

<?php          class osebadgewidget extends wp_widget{          public function osebadgewidget(){              $widget_ops = array(                 'classname' => 'ose-badge-widget',                 'description' => 'show ose firewall badget'             );              $control_ops = array(                 'width' => 200, 'height' => 250,             );              $this->wp_widget('ose_badge_widget', 'ose badge widget', $widget_ops, $control_ops);         }          public function __construct(){              parent:: __construct(                 'ose_badge_widget',                 'ose badge widget',                 array('description' => __('show ose firewall badget'), )             );           }               // show widget appearence         public function form($instance){              if (isset($instance['file_path'])){ $file_path = $instance[ 'file_path' ]; } else { $image_width = __( '', 'text_domain' ); }          ?>             <p>                     <label for="<?php echo $this->get_field_id('file_path' ); ?>"><?php _e( 'file path:' ); ?></label>                      <input class="file_path" id="<?php echo $this->get_field_id( 'file_path' ); ?>" name="<?php echo $this->get_field_name( 'file_path' ); ?>" type="text" value="<?php echo esc_attr( $file_path ); ?>" />             </p>          <?php            }          public function update($new_instance, $old_instance){              $instance['file_path'] = strip_tags( $new_instance['file_path'] );              return $instance;         }          // find image input path, , show         public function widget($args, $instance){              extract($args);              if ($instance['file_path'] != ''){$file_path = $instance['file_path'];} else { $file_path = '';}              $handle = opendir($file_path);             $file = readdir($handle);              echo $before_widget;              echo '<img src= "picture/'.$file.'" border = "0" />';             echo $after_widget;              //$handle = opendir(dirname(realpath(__file__)).'/picture/');             //$file = readdir($handle);               //echo '<img src= "picture/'.$file.'" border = "0" />';         }        }     add_action( 'widgets_init', create_function( '', 'register_widget( "osebadgewidget" );' ) );  ?> 

put code in text widget , move widget want display.

<img src="url of image" alt="text when hovering on it"> 

you can add further code such width , height alter size of well.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -