In this tutorial, i’ll provide the code which sets a default post thumbnail/featured image for all posts in each category. This means all posts which don’t include a featured image, will automatically include the same featured image for that category.
First step is to create a default featured image for each category and upload them using the native Media library in WordPress.
You will then need to find the i.d for each category and the attachment i.d for each image.
Here’s an example:
Permalink: http://example.com/wordpress/?attachment_id=40380 category i.d 22
Permalink: http://example.com/wordpress/?attachment_id=40383 category i.d 23
Permalink: http://example.com/wordpress/?attachment_id=40382 category i.d 24
Each permalink can be viewed by going to Media > Library > Edit Image. Here’s a screenshot:
You can clearly see one category featured image which has been uploaded to the Media Library and the permalink for this image.
At the end of the permalink you can see the attachment i.d for this image which needs to be added to the code below along with the category i.d you want the image to display as your default category featured image.
Once you have all the i.d’s, you can then replace them in this code which needs to be added to the end of your child themes functions.php file.
You can add more else if statements to this code if you know what you’re doing.
The code also includes a default featured image which is set for all other posts not in the categories listed in the code. You can remove these 2 lines of code if you don’t want a global default featured image set for posts which you haven’t added a featured image:
else if ( in_category('56') ) {
set_post_thumbnail($post->ID, '40382');
}
Greg says
just on main home post page
Thanks for the help by the way
Brad Dalton says
Looks like you have other issues there as the padding and margins have been modified.
Are you still using that PHP code in your functions file to add featured images anywhere?
Greg says
Ok now I remember, I chose to bring that image inside the post content area on blog page.
so now I have image left of title and same featured image in content area
any idea on hiding the image left of title on a post
Brad Dalton says
Yes, remove the code which added it from your functions file.
Greg says
Hi Brad, I’ve got a good one for Ya, 🙂
I have a Category as a menu item ‘article”. It shows the posts with the category Article and the read more.
when I click read more I see the full post with an image.
but in the category view no featured post image. I would like to add the featured image from the post to each in the category view. http://realestateradioshow.com/article/
Im not a good coder but can do basic stuff also I use genesis eleven40 as my theme 3.9.1
Thanks your your ideas
Brad Dalton says
Hi Buddy
If you’ve added it as a featured image, it should also display on all archives according to your Genesis > Theme Settings > Content Archive settings. If not, it may be because you added code which over rides this, is that the case?
Greg says
Don’t think so, I did add code to show featured images on main blog page and post pages, as eleven40 didn’t show by default.
would the possible code be in functions of child.
what might I be looking for. that may be commented out
Brad Dalton says
You don’t need to add code to display images on the blog page as the Genesis > Theme Settings > Content Archives control this for featured images so that’s where the problem may be.
Greg says
And that solved it. Thank you
just need to tweek image sizes. 🙂
by the way really enjoy the site. one of my favs
Brad Dalton says
Great! Give me a link if that’s the case. Thanks.
Greg says
after looking around in functions, could this be a problem
Brad Dalton says
Yes, not good code. Where did you get it?
Greg says
Don’t recall, feel like im scraping , with a hint of learning. lol
Brad Dalton says
If you only want to display the images in archives and not single posts, simply remove the PHP code you added to your functions file as its not needed.
Or have i missed something?
Greg says
You will love this one,
Although I am cool with having image on main, archives, and category view.
the original image (same name as featured image) is acting like a second featured image.
and for the life of me i cant figure out how to remove it.
looked at functions code and don’t see it.
Brad Dalton says
Do you mean on single posts or archives?
Greg says
If I remove check box for the image in Genesis > Theme Settings > Content Archive settings.
the second image is still there on home post page
Greg says
Took some of your advice last time we chatted, R&R each add-in till you find the problem.
good advise.
Thank you
Brad Dalton says
Sounds like you got it resolved?
Greg says
Turns out a auto featured image loader addin that worked when archive image is off wants to add a second featured image when archive image is on.
needed to thin out the addins anyway lol.