Har suttit och pillat lite med en widget till Wordpress som slumpvis visar olika bilder jag har liggande i en images-mapp. Nu skulle jag vilja lägga till en option i Wordpress-dashboarden där man skall kunna välja bland tre olika breddar på bilderna (t.ex. 70, 100 och 130px) men jag får det inte att fungera. Jag kan just nu se de tre olika valen av bildstorlek på min dashboard, men hur får jag till det så att bildbredden faktiskt ändras när jag trycker "save"?
Klistrar in hela min kod här, med fel och allt
Klistrar in hela min kod här, med fel och allt
Kod:
<?php /* * Plugin Name: EB Widget * Description: My first widget * Version: 1.0 * Author: Evelina Bjorkdahl * License: GPLv2 */ add_action('widgets_init', function() {register_widget('eb_widget');}); //Vår klass, som får all funktionalitet från WP_Widget class eb_widget extends WP_Widget { //Konstruktor public function __construct() { parent::WP_Widget(false, 'EB Widget', 'description=My first widget'); } //Funktion som skriver ut på skärmen function widget ($args, $instance) { //Vi hämtar in alla argument extract ($args); //Vårt image directory $EBW_IMG_DIR = plugins_url('images/', __FILE__); //Vi väljer en slumpad bild från vårt directory $randomImage = mt_rand(1, 7); //Skriv ut alla argument echo $before_widget; echo $before_title . $instance['title'] . $after_title; echo "<img src='$EBW_IMG_DIR$randomImage.png' width='$width' />"; //Visar vår slumpade bild echo $after_widget; } function update($new_instance, $old_instance) { return $new_instance; } function form() { $title = esc_attr ($instance['title']); $width = esc_attr ($instance['width']); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" /> <label for="<?php echo $this->get_field_id('width'); ?>"> Select width: <select class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('copyright'); ?>" /> <option <?php selected($instance['width'], '70'); ?> value="70">70 px</option> <option <?php selected($instance['width'], '100'); ?> value="100">100 px</option> <option <?php selected($instance['width'], '130'); ?> value="130">130 px</option> </p> <?php } } ?>