how to reference widget variable
-
I want to be able to display different widget options in wordpress options to display based on which dropdown i select. The example shows widget_type dropdown menu, and when I select number one option I want more options to display beneath the widget_type dropdown menu and when two is selected I want some other options to display beneath the widget_type dropdown menu.
<?php class test_Widget extends WP_Widget { function __construct() { parent::__construct( 'test_widget', // Base ID __('test Sidebar', 'text_domain'), // Name array( 'description' => __( 'test sidebar widget.', 'text_domain' ), ) // Args ); } public function widget( $args, $instance ) { $widget_type = apply_filters( 'widget_type', $instance['widget_type'] );; echo $args['before_widget']; echo $args['after_widget']; } public function form( $instance ) { if ( isset( $instance[ 'widget_type'] ) ) { $widget_type = $instance[ 'widget_type' ]; } else { $widget_type = __( '', 'text_domain' ); } ?> <p> <label for="<?php echo $this->get_field_id( 'widget_type' ); ?>">Widget Type:</label> <select class="widefat" id="<?php echo $this->get_field_id( 'widget_type' ); ?>" name="<?php echo $this->get_field_name( 'widget_type' ); ?>"> <option <?php if ( '1' == $instance['widget_type'] ) echo 'selected="selected"'; ?> value="1" value="">1</option> <option <?php if ( '2' == $instance['widget_type'] ) echo 'selected="selected"'; ?> value="2">2</option> </select> </p> <?php } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['widget_type'] = ( $new_instance['widget_type'] ); return $instance; } }how to reference widget variable and add more options based on widget dropdown menu
-
We cannot use the code you posted on WordPress.com, so I’m assuming that you are using WordPress.org.
This means that you are looking for help in the wrong place: these forums provide assistance exclusively for the wp.com platform.
Here are details about the different flavors of WordPress:
http://support.wordpress.com/com-vs-org/
Here is a link to support for wp.org:
http://wordpress.org/support/
- The topic ‘how to reference widget variable’ is closed to new replies.