I'm writing a plugin to display recent posts, however, can't figure out why the thumbnail is not inside the div and "jump" to the header of the page. This is the code from the plugin:
$my_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 5
));
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
$html .="<div class=\"My-container\">";
$html .="<div class=\"My-item\">" . the_post_thumbnail('thumbnail', array('class' => 'My-postImg')) . "</div>";
$html .="<div class=\"My-item-1\">";
$html .= "<p>" . the_category(', ') . " | " . the_time('M. d') . "</p>";
$html .= "<h2>" . get_the_title() . " </h2>";
$html .= "<p>" . the_category(', ') . "</p>";
$html .= "<a href=\"" . get_permalink() . "\" class=\"button\">Read more</a>";
$html .="</div>";
endwhile; endif;
$content .= $html;;
return $content;
another question: I try to display the recent posts at the end of the post. Therefore I have to return the $content after I add it to the $html. Is there cleaner / more efficient way to do this?
Thanks