![](https://i-blog.csdnimg.cn/blog_migrate/91b5bd30ad4b1d30b33b413bdf9970b5.png)
wordpress 缩略图
WordPress has this amazing feature known as Post Thumbnails also referred to as Featured Images. When uploading a post thumbnail, you are asked to add a caption, description, along with other fields, but when you get ready to display it, it only shows the image. In this article, we will share a small trick that will let you display captions or entire image descriptions with your post thumbnail.
WordPress具有此惊人的功能,称为“ 发布缩略图”,也称为“特色图片”。 上载帖子缩略图时,要求您添加标题,说明以及其他字段,但是当您准备显示它时,它仅显示图像。 在本文中,我们将分享一个小技巧,使您可以在发布的缩略图中显示标题或整个图像描述。
First thing first, you need to enable Post Thumbnails in your WordPress Theme. Now, when you upload an image using the media uploader, you will see something like this:
首先,您需要在WordPress主题中启用“ 发布缩略图” 。 现在,当您使用媒体上传器上传图像时,您将看到类似以下内容:
![Add an Image](https://i-blog.csdnimg.cn/blog_migrate/9372aed3e167411a8ce572af031eb4bb.png)
You will need to go ahead and fill all of the information. Now one thing that many folks do not know is that WordPress stores each image as its own post. So the Title of the Image will be the title of the post, Caption will be the excerpt of the post, and Description will be the content of the post. So you can display all of these information when you are displaying your WordPress Thumbnail.
您将需要继续并填写所有信息。 现在,许多人不知道的一件事是WordPress将每个图像存储为自己的帖子。 因此,图像标题将是帖子的标题,标题将是帖子的摘录,描述将是帖子的内容。 因此,当您显示WordPress缩略图时,可以显示所有这些信息。
To display your post thumbnail with its caption, simply paste the following code inside the loop:
要显示带有标题的帖子缩略图,只需将以下代码粘贴到循环中:
<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_excerpt; ?>
You can obviously style it the way you want to style it.
您显然可以按照想要的样式来设置样式。
You can also display entire image description by adding this code inside the post loop:
您还可以通过在post循环内添加以下代码来显示整个图像描述:
<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_content; ?>
This really simple trick can go long way in styling your next custom WordPress theme.
这个非常简单的技巧可以极大地样式化您的下一个自定义WordPress主题。
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-wordpress-post-thumbnails-with-captions/
wordpress 缩略图