Advertisement
Guest User

widget-image-field.php multiple images example

a guest
Jun 10th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. /*
  3.     Plugin Name: Widget Image xing
  4. */
  5.  
  6.  
  7. // we can only use this Widget if the plugin is active
  8. if( class_exists( 'WidgetImageField' ) )
  9.     add_action( 'widgets_init', create_function( '', "register_widget( 'ITI_Widget_Image_OTM' );" ) );
  10.  
  11.  
  12. class ITI_Widget_Image_OTM extends WP_Widget
  13. {
  14.     var $image_field = 'image';
  15.  
  16.     function __construct()
  17.     {
  18.         $widget_ops = array(
  19.                 'classname'     => 'image_otm',
  20.                 'description'   => __( "Image of the Month")
  21.             );
  22.         parent::__construct( 'image_otm', __('Image of the Month'), $widget_ops );
  23.     }
  24.  
  25.     function form( $instance ) {
  26.         $headline = esc_attr( isset( $instance['headline'] ) ? $instance['headline'] : '' );
  27.         $images = array();
  28.         for ( $i = 1; $i <= 3; $i++ ) {
  29.             $image_data = esc_attr( isset( $instance[ $this->image_field . $i ] ) ? $instance[ $this->image_field  . $i ] : 0 );
  30.             $images[] = array( 'count' => $i, 'data' => new WidgetImageField( $this, $image_data ) );
  31.         }
  32.         ?>
  33.         <p>
  34.         <label for="<?php echo $this->get_field_id( 'headline' ); ?>"><?php _e( 'Titel:' ); ?>
  35.         <input class="widefat" id="<?php echo $this->get_field_id( 'headline' ); ?>" name="<?php echo $this->get_field_name( 'headline' ); ?>" type="text" value="<?php echo $headline; ?>" />
  36.         </label>
  37.         </p>
  38.        
  39.        
  40.         <?php
  41.         foreach ( $images as $image ) :
  42.             ?><div>
  43.             <label><?php _e( 'Bild' . $image[ 'count' ] . ':' ); ?></label>
  44.             <?php echo $image[ 'data' ]->get_widget_field( $image[ 'count' ] ); ?>
  45.             </div><?php
  46.         endforeach;
  47.     }
  48.  
  49.     function widget( $args, $instance ) {
  50.         /*
  51.          *
  52.          * muss noch geschrieben werden
  53.          *
  54.          * */
  55.     }
  56.  
  57.     function update( $new_instance, $old_instance )
  58.     {
  59.         $instance = $old_instance;
  60.  
  61.         $instance['headline']            = strip_tags( $new_instance['headline'] );
  62.         for ( $i = 1; $i <= 3; $i++ )
  63.             $instance[ $this->image_field . $i ]    = intval( strip_tags( $new_instance[ $this->image_field . $i ] ) );
  64.         $instance['blurb']               = strip_tags( $new_instance['blurb'] );
  65.  
  66.         return $instance;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement