Show Author Related Posts if they have post
-
Hi,
I’m trying to create a function that will show related author posts only if the author has the posts. It works fine for users who have more than one post, but when users have only one post, it displays some default css styling that looks awkward without the accompanying thumbnails that link to the related posts.
This is what I did in my functions.php:
/********************************************************************/ /* Function for displaying related post thumbnails */ /*********************************************************************/ 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' => 7 ) ); $output = '<div class="tiles-block"><h4 class="other-props" >Other properties by this developer</h4>'; foreach ( $authors_posts as $authors_post ) { $output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . get_the_post_thumbnail($authors_post->ID) . '</a>'; } $output .= '</div>'; return $output; } and this is how I display them through my single.php:
<div class=”row”>
<div class=”col-md-12″>
<?php echo get_related_author_posts(); ?>
</div> <!– col-md-12 –>
</div> <!– end row –>
Obviously I need some kind of if statement, just not sure how….
Any help please? ??
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Show Author Related Posts if they have post’ is closed to new replies.