voceconnect / multi-post-thumbnails

Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
143 stars 63 forks source link

Unable to add a class to the image #20

Closed David-Streck closed 10 years ago

chrisscott commented 10 years ago

Can you clarify is you're asking how this is done or reporting a bug? A code sample would be helpful if you're trying something and it isn't working.

David-Streck commented 10 years ago

I didn't see anything in the documentation.

I've tried adding array('class' => 'alignleft') like you would when normally adding a class to a featured image but it breaks it. Here is an example of what I tried: <?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', array('class' => 'alignleft')); endif; ?>

Any thoughts on how this can be done?

David-Streck commented 10 years ago

Great plugin btw. Thanks for sharing :)

David-Streck commented 10 years ago

@chrisscott is this the right place for this kind of thing? Any thoughts on how I can add a class would be greatly appreciated.

chrisscott commented 10 years ago

Take a look at the function signature for MultiPostThumbnails::the_post_thumbnail():

function the_post_thumbnail($post_type, $id, $post_id = null, $size = 'post-thumbnail', $attr = '', $link_to_original = false)

The array of attr with the class should be passed in as the 5th arg, not 3rd like your sample code. So, your code should probably look something like:

MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', null, 'post-thumbnail', array('class' => 'alignleft'))

David-Streck commented 10 years ago

@chrisscott Thanks! That works!!! :)

pedromarqueslx commented 3 years ago

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail( get_post_type(), 'secondary-image', null, 'post-thumbnail', array('class' => 'img-fluid')); endif; ?>

Thanks! That works!!! :)