Advertisement
Guest User

twitter widget

a guest
Mar 10th, 2012
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.91 KB | None | 0 0
  1.  
  2. /*
  3.     /* ---------------------------- */
  4.     /* -------- Twitter Feeds Widget -------- */
  5.     /* ---------------------------- */
  6. add_action( 'widgets_init', 'trt_twt_widgets' );
  7.  
  8. /*
  9.  * Register widget.
  10.  */
  11. function trt_twt_widgets() {
  12.     register_widget( 'trt_twt_Widget' );
  13. }
  14.  
  15. /*
  16.  * Widget class.
  17.  */
  18. class trt_twt_widget extends WP_Widget {
  19.  
  20.     /* ---------------------------- */
  21.     /* -------- Widget setup -------- */
  22.     /* ---------------------------- */
  23.    
  24.     function trt_twt_Widget() {
  25.    
  26.         /* Widget settings */
  27.         $widget_ops = array( 'classname' => 'trt_twt_widget', 'description' => __('A Triton widget that displays the Twitter Feeds from your twitter account', 'Triton') );
  28.  
  29.         /* Widget control settings */
  30.         /* Create the widget */
  31.         $this->WP_Widget( 'trt_twt_widget', __('Twitter Feeds Widget', 'Triton'), $widget_ops );
  32.     }
  33.  
  34.     /* ---------------------------- */
  35.     /* ------- Display Widget -------- */
  36.     /* ---------------------------- */
  37.    
  38.     function widget( $args, $instance ) {
  39.         extract( $args );
  40.  
  41.         /* Our variables from the widget settings. */
  42.         $title = apply_filters('widget_title', $instance['title'] );
  43.         $count = $instance['count'];
  44.         $cat = $instance['cat'];
  45.  
  46.         /* Before widget (defined by themes). */
  47.         echo $before_widget;
  48.  
  49.         /* Display the widget title if one was input (before and after defined by themes). */
  50.         if ( $title )
  51.             echo $before_title . $title . $after_title;
  52.            
  53.         /* Display a containing div */
  54.         echo '<div class="trt_twitter"><ul id="twitter_update_list"></ul><script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/' . $cat . '.json?callback=twitterCallback2&amp;count=' . $count . '"></script>';
  55.         echo '</div>';
  56.  
  57.         /* After widget (defined by themes). */
  58.         echo $after_widget;
  59.     }
  60.  
  61.     /* ---------------------------- */
  62.     /* ------- Update Widget -------- */
  63.     /* ---------------------------- */
  64.    
  65.     function update( $new_instance, $old_instance ) {
  66.         $instance = $old_instance;
  67.  
  68.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  69.         $instance['title'] = strip_tags( $new_instance['title'] );
  70.  
  71.         /* No need to strip tags */
  72.         $instance['count'] = $new_instance['count'];
  73.         $instance['cat'] = $new_instance['cat'];
  74.  
  75.         return $instance;
  76.     }
  77.    
  78.     /* ---------------------------- */
  79.     /* ------- Widget Settings ------- */
  80.     /* ---------------------------- */
  81.    
  82.     /**
  83.      * Displays the widget settings controls on the widget panel.
  84.      * Make use of the get_field_id() and get_field_name() function
  85.      * when creating your form elements. This handles the confusing stuff.
  86.      */
  87.    
  88.     function form( $instance ) {
  89.    
  90.         /* Set up some default widget settings. */
  91.         $defaults = array(
  92.         'title' => '',
  93.         'count' => '5',
  94.         'cat' => 'towfiqi',
  95.         );
  96.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  97.  
  98.         <!-- Widget Title: Text Input -->
  99.         <p>
  100.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'Triton') ?></label>
  101.             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  102.         </p>
  103.        
  104.         <!-- Category of Posts: Text Input -->
  105.         <p>
  106.             <label for="<?php echo $this->get_field_id( 'cat' ); ?>"><?php _e('Account ID:', 'Triton') ?></label>
  107.             <input class="widefat" id="<?php echo $this->get_field_id( 'cat' ); ?>" name="<?php echo $this->get_field_name( 'cat' ); ?>" value="<?php echo $instance['cat']; ?>" />
  108.         </p>
  109.  
  110.         <!-- Number of Posts: Text Input -->
  111.         <p>
  112.             <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e('Number of Posts:', 'Triton') ?></label>
  113.             <input class="widefat" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" value="<?php echo $instance['count']; ?>" />
  114.         </p>
  115.        
  116.        
  117.     <?php
  118.     }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement