Load_TextDomain(); // Setup the Widget data $this->WP_Widget ( False, $this->t('Random Posts Widget'), Array('description' => $this->t('This Widget shows some random posts on your sidebar.'))); // Register as Widget Add_Action ('widgets_init', Array($this, 'Register')); } Function Register(){ Register_Widget(get_class($this)); } Function Load_TextDomain(){ $this->text_domain = get_class($this); load_textdomain ($this->text_domain, DirName(__FILE__).'/language/'.get_locale().'.mo'); } Function t ($text, $context = ''){ // Translates the string $text If ($context == '') return __($text, $this->text_domain); Else return _x($text, $context, $this->text_domain); } Function widget ($widget_args, $settings){ // Check inputs If ($settings['title'] == Null) $settings['title'] = $this->t('Random Posts'); $settings['limit'] = IntVal ($settings['limit']); If ($settings['limit'] <= 0) $settings['limit'] = 5; // Read posts $arr_post = (array) get_posts(Array( 'post_type' => 'post', 'numberposts' => $settings['limit'], 'caller_get_posts' => 1, 'exclude' => get_the_id(), 'orderby' => 'rand' )); // Check if there are posts If (Empty($arr_post)) return False; // Widget output Echo $widget_args['before_widget']; // Widget title Echo $widget_args['before_title'] . $settings['title'] . $widget_args['after_title']; Echo ''; // Widget bottom Echo $widget_args['after_widget']; } Function form ($settings){ // Check inputs If ($settings['title'] == Null) $settings['title'] = $this->t('Random Posts'); $settings['limit'] = IntVal ($settings['limit']); If ($settings['limit'] <= 0) $settings['limit'] = 5; ?>

t('Title:') ?>

t('Number of posts:') ?>