Featured Image Not Showing in Wordpress

2019-09-07 23:26发布

问题:

I'm trying to show a featured image in Wordpress, I've uploaded the image (put it as the smallest image possible) but when I view the blog list view (category.php) I just get the blog post header, and no image.

Anybody know how to show the image? Checked the source, and doesn't show an image at all.

Hope someone can help, would be much appreciated.

回答1:

In addition to setting the featured image in WP admin, you need rendering code somewhere in your template files. Something like this:

if ( has_post_thumbnail( get_the_ID() ) ) {
    echo get_the_post_thumbnail( get_the_ID() );
}

I use this code in my header.php theme file, but you may prefer it within page.php or elsewhere (category.php seems appropriate in your case).

Check the documentation for help changing the dimensions, adding class attributes, etc. to the <img/> tag generated.

http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail



标签: php wordpress