0

So 'Featured image' option on WP is lacking. What I was expecting is when user selects multiple images it echos out multiple images on the page, instead you can only select one photo. I tried to find some plugin to do exactly that, but no luck. It seems easy to do and I wouldn't like any additional plugins.

Can anybody do that so when I type

<?php the_post_thumbnails('index-thumb'); ?>

it returns:

<img src="..."...
<img src="..."...

Any help is much appreciated! Thank you! ;)

  • 1
    If it's easy to do, what's the problem? ;) The featured image functionality is for just that - a single featured image. If you want more, try the Multiple Post Thumbnails plugin. – vancoder Oct 9 '15 at 16:14
0

Its certainly not a few liner code. So its better to use a Feature Gallery plugin. I just tried that which works perfectly fine and you can use below code to get the images in Featured Gallery.

<?php $galleryArray = get_post_gallery_ids($post->ID);  
      foreach ($galleryArray as $id) { ?>   
         <img src="<?php echo wp_get_attachment_url( $id ); ?>"> 
<?php }?>

Please refer plugin description to get more details about the code.

  • I'll try to implement it into my code and let you know how it goes. Thanks for your answer! – pbe Oct 9 '15 at 19:01
  • Installed the plugin, but how to make a 'featured gallery post' a custom post type? Tried to insert the code author of the plugin gave into functions.php but it breaks the plugin. My loop looks like this get_template_part( 'template-parts/content', get_post_format() ); so it's capable of custom post formats. What I am doing wrong? – pbe Oct 10 '15 at 8:45
  • I think there must be some mistake in code which you used provided by plugin author. Most probably you forgot to change the slug as per the actual post format. Please refer below code wherein I used 'header-image' slug of my custom post type and that worked fine. function add_featured_galleries_to_ctp( $post_types ) { return array('header-image'); } add_filter('fg_post_types', 'add_featured_galleries_to_ctp' ); – Prasad Nevase Oct 10 '15 at 13:09
  • Did it work or you are still facing problem? – Prasad Nevase Oct 11 '15 at 4:34
  • I used if ( !empty(get_post_gallery_ids($post->ID)) ) to differentiate if post has featured gallery or not, imo better way than creating additional post type, and having user to select the post type. Took me like half of day to figure this out but it works great. Thanks for your answer it pointed me in the right direction. Thanks again! – pbe Oct 11 '15 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.