Updated on March 17, 2017
A user asked in Genesis Facebook group,
I want to add the option to select an alternate image in Genesis Sandbox Featured Content widget, as opposed to using the post or page featured image.
I advised the user to switch to the newer, better and actively developed Genesis Featured Posts Combo (commercial plugin) from the Sandbox plugin. One of the built-in features of GFPC is a fallback image which when set will be shown on the front end when an entry does not have a featured image.
But re-reading the user's question, I realized that the requirement is to display an alterante image which if set, should be shown instead of the featured image. This is not the same as fallback image because fallback image applies to all entries of a GFPC widget instance where as alternate image is specific to a particular entry (Page or Post etc.).
In this tutorial I show how we can use Advanced Custom Fields to create a custom image field attached to Posts and Pages followed by displaying this image instead of the entry's featured image when output via GFPC widget.
Step 1
Install and activate Advanced Custom Fields. Create a custom field group having a alternate_image
image field and attach it to Posts and/or Pages [depending on what you would like to be shown in the featured widget(s)].
Step 2
Edit your Pages/Posts for which you would like to use the alternate images and set them.
Step 3
Add the following in child theme's functions.php:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Fantastico! Worked right out of the box, thank you sooooooo much, Sridhar!
I’m ba-ack! Don’t know what I did, but while this is swapping images nicely, there is a problem.
Clicking on the in the GFPC widget links to the post, however, clicking on the links to the image attachment page.
I broke it. Can you help?
where is the edit link on here, lol?
should say “clicking on the GFPC widget TITLE links to the post, however, clicking on the GFPC IMAGE links to the image attachment page, rather than to the post.”
I have updated the post with fixed code so that the image links to entry’s permalink rather than to full image.
so, clicking on the GFPC alternate images goes to /wp-content/uploads
okay, i found it. chinmoy had given me code to help pull different CPTs into the widget, bypassing selected post type in the widget dropdown selector (which didn’t work, he says i need to add loops,) in any case that was causing the problem. nothing to do w your code.
// Pull Multiple CPTs from GFPC by widget ID Chinmoy
//add_filter( ‘gfpc_query_args_gfpc-widget-7’, ‘gfpc_post_from_cpts’, 99, 2 );
//function gfpc_post_from_cpts( $args, $instance ) {
//$args[‘post_type’] = array( ‘stay’, ‘restaurant’, ‘outdoors’ );
//return $args;
//}
Fantastic tutorial as always, Sridhar. Would it be possible to take this one step further?
Let’s say there are 2 GFPC widgets on the page, each displaying 1 featured post from different categories. If a post is assigned to both of those categories, the same image will appear in both GFPC widgets. Is there a way to have it check to see if both GFPC widgets are displaying the same post, and then use an alternative image for only 1 of the GFPC widgets? So one GFPC widget would display the default featured image and the other GFPC widget would display the alternative image from ACF.
Tried to implement on my child theme and doesn’t seem to do anything. Maybe this is only compatible with old version of Genesis. This looks about 2 yrs old. Wish it worked, trying to use different size image on homepage widget vs featured image.
This may sound obvious, but do you have Genesis Featured Posts Combo plugin installed and activated?
Yep absolutely. the widget shows up with the 3 titles of the posts, but alternate_image does not display.
Perhaps I don’t have the widget configured correctly? If I tick the box display show featured image, 6 images appear.
3 images that are the same are the featured image, which shouldn’t be displayed. The other 3 images are the correct images to be displayed.
if I untick the box, no images appear.
http://wilkie.staging.wpengine.com/
I’ve updated the code to fix this problem which crept up due to a plugin update.
Thanks! Working as expected now!