|
1 <?php |
|
2 class ocmx_flickr_widget extends WP_Widget { |
|
3 /** constructor */ |
|
4 function ocmx_flickr_widget() { |
|
5 parent::WP_Widget(false, $name = 'OCMX Flickr Photos', $description = 'Display your latest Flickr Photos.'); |
|
6 } |
|
7 |
|
8 /** @see WP_Widget::widget */ |
|
9 function widget($args, $instance) { |
|
10 extract( $args ); |
|
11 $flickr_key = $instance["flickr_id"]; |
|
12 $flickr_count = $instance["flickr_count"]; |
|
13 $flickr_src = "http://www.flickr.com/badge_code_v2.gne?count=".$flickr_count."&display=latest&size=s&layout=x&source=user&user=".$flickr_key; |
|
14 ?> |
|
15 <div id="flickr_badge_wrapper" class="clearfix"> |
|
16 <script type="text/javascript" src="<?php echo $flickr_src ?>"></script> |
|
17 </div> |
|
18 <?php |
|
19 } |
|
20 |
|
21 /** @see WP_Widget::update */ |
|
22 function update($new_instance, $old_instance) { |
|
23 return $new_instance; |
|
24 } |
|
25 |
|
26 /** @see WP_Widget::form */ |
|
27 function form($instance) { |
|
28 $flickr_id = esc_attr($instance["flickr_id"]); |
|
29 $flickr_count = esc_attr($instance["flickr_count"]); |
|
30 |
|
31 ?> |
|
32 <p><label for="<?php echo $this->get_field_id('flickr_id'); ?>">Flickr ID<input class="widefat" id="<?php echo $this->get_field_id('flickr_id'); ?>" name="<?php echo $this->get_field_name('flickr_id'); ?>" type="text" value="<?php echo $flickr_id; ?>" /></label></p> |
|
33 <p>Get your Flickr ID from <a href="http://idgettr.com/" target="_blank">idGettr</a></p> |
|
34 <p> |
|
35 <label for="<?php echo $this->get_field_id('flickr_count'); ?>">Image Count |
|
36 <select size="1" class="widefat" id="<?php echo $this->get_field_id('flickr_count'); ?>" name="<?php echo $this->get_field_name('flickr_count'); ?>"> |
|
37 <?php for($i = 1; $i < 11; $i++) : ?> |
|
38 <option <?php if($flickr_count == $i) : ?>selected="selected"<?php endif; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 <?php endfor; ?> |
|
40 </select> |
|
41 </p> |
|
42 <?php |
|
43 } |
|
44 |
|
45 } // class FooWidget |
|
46 |
|
47 //This sample widget can then be registered in the widgets_init hook: |
|
48 |
|
49 // register FooWidget widget |
|
50 add_action('widgets_init', create_function('', 'return register_widget("ocmx_flickr_widget");')); |
|
51 |
|
52 ?> |