I would like to have two different sized featured images on my homepage. I currently have all featured images set to 280×200. I would like to have SOME posts on the home page display a larger 620×200 image and others the 280×200. I’m not sure how to accomplish this. I realize I can specify a custom image size in my functions file like add_image_size( 'large-image', 620, 200, true );
. However, I’m not sure how to get my homepage to know which image to display?
I have no idea if this is an optimal approach or not but I was thinking of making a custom field called ‘large-featured’ and having the homepage check to see if large-featured
custom field value is set to true. Upon true use large-image
custom size and upon no custom field value set use wordpress default featured size.
I’m not good at php coding so a little help here would be awesome. I’m pretty good and figuring things out with a little direction. Thanks for your assistance. Much appreciated.
My site in question is: http://www.fighterstyle.com
With
get_post_thumbnail()
you have the ability to insert a featured image in your theme.the_post_thumbnail( $size, $attr );
holds to parameter 1. The size of your image and the ID.If you would like to have 2 image sizes of featured images on your home page you could do it like this:
Your idea of using a custom field sounds good to me. You can then access this data using the
get_post_meta
function as described in the codex, and use that to pass the values of the size.As to what values to pass, instead of passing hard coded sizes, it’s better if you define the desired sizes in the
Settings -> media
screen, and then you can use the WP keywords thumbnail, medium, large or full when calling theget_the_post_thumbnail
functionFirst, I think you have to add new size if it not implement yet:
The media uploader will create the images in the currect size from now.
If you have old images it will not regenerate the images to the new size, use
AJAX Thumbnail Rebuild
plugin.Now you can call:
Create custom field – large_featured. If the value = 1 the large standard size will be displayed. Else – medium.
You can create additional image sizes specifically for your homepage by adding this in functions.php:
I suggest you to get the url of the thumbnail image instead of the thumbnail image which is already resized when you set it as featured image…
Look in the functions.php of the theme you are using and you can easily change:
I also used another function on one of my sites
A featured image is saved as an attachment ID, you can use the
get_post_thumbnail
function as a shortcut to grabbing other sizes like this: