特色图片未在 Wordpress 中显示 [英] Featured Image Not Showing in Wordpress
问题描述
我正在尝试在 Wordpress 中显示特色图片,我已经上传了图片(尽可能将其作为最小的图片)但是当我查看博客列表视图 (category.php) 时,我只看到了博客文章标题,并且没有图像.
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.
推荐答案
除了在 WP admin 中设置特色图像外,您还需要在模板文件中的某处添加渲染代码.像这样:
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() );
}
我在我的 header.php
主题文件中使用此代码,但您可能更喜欢在 page.php
或其他地方 (category.php
> 似乎适合您的情况).
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).
查看文档以获取更改维度、将类属性等添加到生成的 <img/>
标记的帮助.
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
这篇关于特色图片未在 Wordpress 中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!