wordpress get_the_post_thumbnail()没有显示任何内容
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:
<?php
$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>
</div>
<?php
endforeach;
wp_reset_postdata();
?>
I'm using HTML5Blank Theme. And it supports thumbnails. this is the code for it in my functions.php file:
add_theme_support('post-thumbnails');
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);
我正在创建我的第一个wordpress主题,我无法弄清楚为什么帖子缩略图没有显示。 它什么都不做(没有错误)。 这是我的代码: p>
&lt;?php
$ args = array('posts_per_page'=&gt; 3,'category'=&gt; 6);
$ postslist = get_posts($ args);
foreach($ postslist as $ post):
setup_postdata($ post);
?&gt;
&lt; div class =“col-xs-12 col-sm-4 “&gt;
&lt; h4&gt;&lt;?php the_title(); ?&gt;&lt; / h4&gt;
&lt;?php get_the_post_thumbnail('small'); ?&gt;
&lt; p&gt;&lt;?php the_excerpt(); ?&gt;&lt; / p&gt;
&lt; / div&gt;
&lt;?php
endforeach;
wp_reset_postdata();
?&gt;
code> pre>
我正在使用HTML5Blank主题。 它支持缩略图。 这是我在functions.php文件中的代码: p>
add_theme_support('post-thumbnails');
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);
pre>
div>
You need to echo it like this 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.
I think this is a small typing error: samll -> small
the the_post_thumbnail function also used for get post image you can also do by this way.
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('small');
}
?>