Load_TextDomain(); // Setup the Widget data $this->WP_Widget ( False, $this->t('Post navigation Widget'), Array('description' => $this->t('You can use this Widget to show the next or previous post link on single post views.'))); // 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){ If ($settings['show_post'] == 'next' || $settings['show_post'] == Null){ // Try to show the next post If ($selected_post = get_next_post()) $post_link_text = $this->t('Read next post'); ElseIf ($selected_post = get_previous_post()) $post_link_text = $this->t('Read previous post'); } ElseIf ($settings['show_post'] == 'prev'){ // Try to show the previous post If ($selected_post = get_previous_post()) $post_link_text = $this->t('Read previous post'); ElseIf ($selected_post = get_next_post()) $post_link_text = $this->t('Read next post'); } Else { // Here we can't do anymore return False; } // Extract the data $post_title = $selected_post->post_title; $post_excerpt = $this->get_the_excerpt($selected_post->ID); $post_link = get_permalink($selected_post->ID); // Widget output Echo $widget_args['before_widget']; // Widget title Echo $widget_args['before_title'] . $post_title . $widget_args['after_title']; // Post excerpt Echo '

' . $post_excerpt . '

'; // Link to the post Echo '

'.$post_link_text.'

'; // Widget bottom Echo $widget_args['after_widget']; } Function form ($settings){ ?>

/> t('Try to show the next post. If there is no next post try to show the previous post.') ?>

/> t('Try to show the previous post. If there is no previous post try to show the next post.') ?>

post_excerpt != ''){ // get the users excerpt $excerpt = $post->post_excerpt; } Else { // Create the excerpt $excerpt = $post->post_content; $excerpt = strip_shortcodes( $excerpt ); $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); $excerpt = strip_tags($excerpt); $excerpt_length = apply_filters('excerpt_length', 55); $excerpt_more = apply_filters('excerpt_more', '[...]'); $words = explode(' ', $excerpt, $excerpt_length + 1); If ( Count($words) > $excerpt_length ){ Array_Pop($words); Array_Push($words, $excerpt_more); $excerpt = Implode(' ', $words); } } // Run filters - there is a bug if you try to run an empty excerpt through the filter If ($excerpt != '') $excerpt = apply_filters('get_the_excerpt', $excerpt); return $excerpt; } } /* End of Class */ New wp_plugin_widget_post_navigation(); } /* End of If-Class-Exists-Condition */ /* End of File */