Sadegh Shaikhi Sadegh Shaikhi - 1 year ago 85
PHP Question

wordpress get_the_post_thumbnail() doesn't show anything

I'm creating my first wordpress theme, I can't figure out why the post thumbnails aren't showing. it just does nothing(no errors). Here is my code:

$args = array( 'posts_per_page' => 3, 'category' => 6);
$postslist = get_posts( $args );
foreach ( $postslist as $post ) :
setup_postdata( $post );
<div class="col-xs-12 col-sm-4">
<h4><?php the_title(); ?></h4>
<?php get_the_post_thumbnail('small'); ?>
<p><?php the_excerpt(); ?></p>


I'm using HTML5Blank Theme. And it supports thumbnails. this is the code for it in my functions.php file:

add_image_size('large', 700, '', true);
add_image_size('medium', 250, '', true);
add_image_size('small', 120, '', true);
add_image_size('custom-size', 700, 200, true);

Answer Source

You need to echo it like this <?php echo get_the_post_thumbnail('small'); ?>
get_ functions store the data, they don't actually return it which is why you have to echo. They are useful in many cases like you could store it in a variable like $thumb-small = get_the_post_thumbnail('small'); and reuse it throughout the page.