samedi 26 décembre 2015

How can I make a multi select widget in wordpress?

I have got problems with my Wordpress plugin. I tried to make a button widget which has multiple options in the backend. My problem is that the title is being saved but not the options in the select tag. Here is the piece of code:

<code>add_action( 'widgets_init', function(){
 register_widget( 'Button_Widget' );
});
   class Button_Widget extends WP_Widget {





/**
 * Register widget with WordPress.
 */
function __construct() {
    parent::__construct(
        'Button_Widget', // Base ID
        __('♦ Button', 'text_domain'), // Name
        array('description' => __( 'Insert a button', 'text_domain' ),) // Args
    );
}






/**
 * Front-End Widget
 */
public function widget( $args, $instance ) { 

    //coming soon


}





/**
 * Back-end widget form.
 */
public function form( $instance ) {

    ?>

/**
 * Back-end widget form.
 *
 * @see WP_Widget::form()
 *
 * @param array $instance Previously saved values from database.
 */
    if ( isset( $instance[ 'title' ] ) ) {
        $title = $instance[ 'title' ];
    }
    else {
        $title = __( 'New title', 'text_domain' );
    }
    ?>
    <p>
        <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
    </p>

    <p>
        <label>Animaton:</label>
        <select>
            <option value="slide">Slide</option>
            <option value="fade">Fade</option>
            <option value="bounce">Bounce</option>
        </select>

        <label>Color:</label>
        <select>
            <option value="white">White</option>
            <option value="red">Red</option>
            <option value="green">Green</option>
        </select>
    </p>





<?php 
   }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire