Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on flickr Wp-widget. Here is code to fetch flickr pics.

class imperia_flickr extends WP_Widget {

    function imperia_flickr() {
        $widget_ops = array('description' => 'This Flickr widget populates photos from a Flickr ID.' );

        parent::WP_Widget(false, __('imperia - Flickr', 'imperiathemes'),$widget_ops);      
    }

    function widget($args, $instance) {  
        extract( $args );
        $id = $instance['id'];
        $number = $instance['number'];

        echo $before_widget;
        echo $before_title; ?>
        <div class="flickr-icon"></div>
        <?php _e('Photostream'); ?>
            <?php echo $after_title; ?>
            <script type="text/javascript">
            $(document).ready(function() {
            $('#flickr').jflickrfeed({
            limit: <?php echo $number; ?>,
            qstrings: {
            id: '<?php echo $id; ?>'
          },
            itemTemplate: '<li><a href="{{image_b}}" rel="prettyPhoto[pp_gal]"><img class="flickr" src="{{image_s}}" alt="{{title}}" width="45" height="45"></a></li>'
          }, function(data) {
          $('#flickr a').prettyPhoto();
          });   
            }); 
            </script>        
            <ul id="flickr"></ul>
            <div class="clear"></div>
       <?php            
       echo $after_widget;
   }

   function update($new_instance, $old_instance) {                
       return $new_instance;
   }

   function form($instance) {        
    ******  $id = esc_attr($instance['id']);
    ******  $number = esc_attr($instance['number']);
        ?>
        <p>
            <label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Flickr ID (<a href="http://www.idgettr.com">idGettr</a>):','imperiathemes'); ?></label>
            <input type="text" name="<?php echo $this->get_field_name('id'); ?>" value="<?php echo $id; ?>" class="widefat" id="<?php echo $this->get_field_id('id'); ?>" />
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number:','imperiathemes'); ?></label>
            <select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>">
                <?php for ( $i = 1; $i <= 12; $i += 1) { ?>
                <option value="<?php echo $i; ?>" <?php if($number == $i){ echo "selected='selected'";} ?>><?php echo $i; ?></option>
                <?php } ?>
            </select>
        </p>
        <?php
    }
} 

register_widget('imperia_flickr');

This widget works fine but gives following error

-- Debug: Undefined index: id on line 54 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php
-- Debug: Undefined index: number on line 55 of /wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php

I have marked these lines with ** above.

Where I'm going wrong ? What needs to be fixed ?

Thanks

share|improve this question

1 Answer 1

up vote 4 down vote accepted

You should use isset

$id = isset( $instance['id'] ) ? esc_attr( $instance['id'] ) : '';
$number = isset( $instance['number'] ) ? esc_attr( $instance['number'] ) : '';
share|improve this answer
    
after using isset my page is completely broken & I get error : Parse error: syntax error, unexpected ':' in /Volumes/STUDIO/Workspace/WP - WS/gamma/wp-content/themes/imperia/includes/widgets/widget-imperia-flickr.php on line 55 –  MANnDAaR Aug 9 '11 at 11:56
    
I fixed the code. –  t31os Aug 9 '11 at 12:01
    
Thanks t31os, missed that while editing. @MANnDAaR now code will work properly –  Mamaduka Aug 9 '11 at 12:03
    
Thanks @t31os & Mamaduka. It works now... –  MANnDAaR Aug 9 '11 at 12:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.