/ Published in: PHP
Displays latest posts by current author (place it within the loop). Adapted from code from [here](http://www.wpbeginner.com/wp-tutorials/how-to-display-related-posts-by-same-author-in-wordpress/) and a tutorial [here](http://www.makeuseof.com/tag/how-to-create-wordpress-widgets/)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Plugin Name: Latest posts by current author Plugin URI: http://podojdi.ru/ Description: Displays latest posts by current author (place it within the loop). Adapted from code from <a target="_blank" href="http://www.wpbeginner.com/wp-tutorials/how-to-display-related-posts-by-same-author-in-wordpress/">here</a> and a <a href="http://www.makeuseof.com/tag/how-to-create-wordpress-widgets/" target="_blank">tutorial here</a> Author: Alexander Belyaev Version: 1.0 Author URI: http://podojdi.ru/ */ class LatestByAuthorWidget extends WP_Widget { function LatestByAuthorWidget() { $widget_ops = array('classname' => 'LatestByAuthorWidget', 'description' => 'Displays latest posts by current author' ); $this->WP_Widget('LatestByAuthorWidget', 'Latest posts by current author', $widget_ops); } function form($instance) { $title = $instance['title']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> <?php } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = $new_instance['title']; return $instance; } function widget($args, $instance) { echo $before_widget; echo $before_title . $title . $after_title; // WIDGET CODE GOES HERE global $authordata, $post; if ($authors_posts) { $output = '<ul>'; foreach ( $authors_posts as $authors_post ) { $output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>'; } $output .= '</ul>'; echo $output; } else {echo '<div class="notice">L\'autore ha ancora pubblicato solo questo post.</div>';}; echo $after_widget; } } add_action( 'widgets_init', create_function('', 'return register_widget("LatestByAuthorWidget");') );?>