I want to keep different image on the single post type page and a different image if the post type is showing in a loop. Is there any way?
Perhaps we can use the gallery image as featured on single view but if so, how?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI want to keep different image on the single post type page and a different image if the post type is showing in a loop. Is there any way?
Perhaps we can use the gallery image as featured on single view but if so, how?
The easiest way to achieve this is to use the Multiple Post Thumbnails plugin. Once you have done this, add the following snippet to your functions file:
if (class_exists('MultiPostThumbnails')) {
new MultiPostThumbnails(array(
'label' => __('Secondary Featured Image', 'yourtextdomain')
'id' => 'secondary-image',
'post_type' => 'post'
));
}
This will make a box 'Secondary Featured Image' available on your edit post page. Now you will have to place it in your theme, wherever you want the secondary featured image to appear in stead of the primary:
if (class_exists('MultiPostThumbnails'))
MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');
else
the_post_thumbnail(); //fallback in case somebody doesn't have the plugin installed
'post_type' => 'post'
, but I don't know to what post type, because I don't know how your custom post type is defined. The second snippet would go into the template file where you want the secondary featured image to display. For instance, if you want it on single pages, open single.php
and replace the_post_thumbnail
in that file with the snippet.
– cjbj
Jun 6 '16 at 14:20