admin管理员组

文章数量:1122832

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?

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?

Share Improve this question edited Jun 6, 2016 at 12:54 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 6, 2016 at 12:08 Irfan SaleemIrfan Saleem 111 bronze badge 1
  • if you just want a different image size of the same image, you can do that a bit simpler, otherwise use @cjbj's solution. – majick Commented Jun 6, 2016 at 14:42
Add a comment  | 

1 Answer 1

Reset to default 0

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 thumbnailsDifferent Featured Images depending on context loop or single view