samedi 27 décembre 2014

dropdown in widget. showing value in dropdown


I am making a widget. I have created a dropdown with some values



<label for="<?php echo $this->get_field_id('postcontent'); ?>"><?php _e( 'Select post content:' )?></label>
<select id="<?php echo $this->get_field_id('postcontent'); ?>" name="<?php echo $this->get_field_name('postcontent'); ?>">
<option value="none" selected="selected"><?php echo __('None','alliance'); ?></option>
<option value="owl"><?php echo __('Full post with Image', 'alliance'); ?></option>
<option value="post"><?php echo __('Post content', 'alliance'); ?></option>
</select>


When I save the page, the correct value does get saved to the database; however, when the page finishes reloading, the dropdowns value shows "None" which is the first option in the list. How do I get it to show the selected value?


I tried using the select() function but did not have any luck with it. When I check my dropdown, nothing showed in the code. I also tried using select="selected" and that made the last option always show.


Here it is with the select()



<label for="<?php echo $this->get_field_id('postcontent'); ?>"><?php _e( 'Select post content:' )?></label>
<select id="<?php echo $this->get_field_id('postcontent'); ?>" name="<?php echo $this->get_field_name('postcontent'); ?>">
<option value="none" <?php selected($postcontent, 'None',false); ?>><?php echo __('None','alliance'); ?></option>
<option value="owl" <?php selected($postcontent, 'Full post with Image',false); ?> ><?php echo __('Full post with Image', 'alliance'); ?></option>
<option value="post" <?php selected($postcontent, 'Post Content',false); ?> ><?php echo __('Post content', 'alliance'); ?></option>
</select>




Aucun commentaire:

Enregistrer un commentaire