Display related posts by the same author
This snippet is useful for creating a small platform blog or if you need to create a small social site using WordPress.. Exactly, I'm sure, that the WordPress platform is quite suitable for large projects and there are all the tools for this. Another thing is that it was not created for this..
So, back to our code snippets. Below is a code snippet, by adding which you will get related articles by the same author.
1 2 3 4 5 6 7 8 9 10 |
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; } |
To display related posts, use the code:
1 |
<?php echo get_related_author_posts(); ?> |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.