WordPress related posts

Add Tool

Display WordPress related posts By Current Author


Display WordPress related posts By Current Author

Most themes show WordPress related posts underneath a post that are related to the post topic. This function lets you display WordPress related posts from the same post author.

function get_related_author_posts() {
    global $authordata, $post;
    $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
    $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>';
    return $output;
}

After adding the above function to functions.php make sure you add the below code snippet to your single.php template.

<?php echo get_related_author_posts(); ?>

Tags: wordpress related posts, related posts wordpress, wordpress related posts plugin, wordpress related posts widget, wordpress plugin related posts
Payza

About Masum Billah

Display WordPress related posts By Current Author Hi I am Md. Masum Billah Contributor of this website. I always like to share various things with other. In this website I am sharing web design related tips and tricks, necessary web development tools, source codes for beginner and advance web developer.


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: WordPress related posts


adf.ly