Show Related Author Post Without Any Plugin

In WordPress author page or in a single post page you can show related posts of current author. For the visitors it is really useful if he or she like the author and want to access all the related post of that author. you can use many plugin but here we are going to show you how to show related author Post without any plugin. You can do it by only adding a simple function to your active theme function. So lets learn the function.

 

First of all add this function to your theme’s functions.php file:

[html]

function get_related_posts_of_this_author() {
global $authordata, $post;
$authors_posts = get_posts( array( ‘author’ => $authordata->ID, ‘post__not_in’ => array( $post->ID ), ‘posts_per_page’ => 6 ) );
$output = ‘<h2>Check Other Post by This Author:</h2><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>’;
return $output;
}

[/html]

Change the number 6 if you want to show more posts. Then just add the following code where you want to show the list. In general we add it in single.php file:

[html]<?php echo get_related_posts_of_this_author(); ?>[/html]

And here is the output:

related-author-post1

Author: mytutorialguru

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *