In a previous post, we created a new size for your images on ours WordPress site.
Let’s display them in our template. Let’s start with the basic functions for working with post thumbnails
has_post_thumbnail() – allows check if thumbnail has been set for your post
the_post_thumbnail() – Allows output post thumbnail in cycle and set the size in the parameters
get_post_thumbnail_id() – Will help get post thumbnail id (example: 141)
get_the_post_thumbnail() – similar to has_post_thumbnail() function, which takes more parameters used when you need to get the data of this function for processing in PHP.
In our example we will use the most advanced function get_the_post_thumbnail().
We insert the code into the file single.php, depending on the output place, may change method getting ID for post thumbnail:
if (has_post_thumbnail(get_the_ID())) { echo get_the_post_thumbnail(get_the_ID(), 'newsizeimagename') }
newsizeimagename – сustom image size created by you