Revision: 56526
Updated Code
at April 2, 2012 04:46 by certainlyakey
Updated Code
<?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) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $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) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) echo $before_title . $title . $after_title; // WIDGET CODE GOES HERE global $authordata, $post; $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 7 ) ); 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");') );?>
Revision: 56525
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 2, 2012 02:01 by certainlyakey
Initial Code
<?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 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/ 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) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $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) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) echo $before_title . $title . $after_title; // WIDGET CODE GOES HERE global $authordata, $post; $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 7 ) ); $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; echo $after_widget; } } add_action( 'widgets_init', create_function('', 'return register_widget("LatestByAuthorWidget");') );?>
Initial URL
Initial Description
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/)
Initial Title
Latest posts by current author widget plugin for Wordpress 3+
Initial Tags
php, plugin, wordpress
Initial Language
PHP