Closed jorditost closed 11 years ago
Don't add the custom thumbnail when editing the post, but add it through the Media gallery. This way, the image won't be attached to the post and won't show up in the gallery.
Alternatively, you could set the specific images you want to use in the gallery instead of using the default empty gallery tag.
Hi Chris, thanks for your reply. It would work, but I think it's not a good user-friendly solution.
I could program a function that loads the gallery excluding the custom thumbnails.
Is there a way to list all custom thumbnail IDs automatically? For example, a function that returns:
array("secondary-featured-image", "home-image")
It would be very useful!
Thanks for your help!
An option that may work: filter post_gallery
and in that filter use MultiPostThumbnails::get_post_thumbnail_id()
to get the thumbnail(s) for each thumbnail you have registered for that post. Add the post id's of the thumbnails to the exclude
key of the $attrs
passed in to the filter, remove the post_gallery
filter added and then call gallery_shortcode($attrs)
with the updated $attrs
and use that as the return value of your filter.
Something like:
add_filter('post_gallery', 'my_filter');
function my_filter($attrs) {
/* e.g for a thumbnail registered with: new MultiPostThumbnails(
array(
'label' => 'Secondary Image',
'id' => 'secondary-image',
'post_type' => 'post'
)
);
*/
if ($exclude_id = MultiPostThumbnails::get_post_thumbnail_id('post', 'secondary-image', $attr['id'])) {
$attrs['exclude'] = $exclude_id;
}
remove_filter('post_gallery', 'my_filter');
return gallery_shortcode($attrs);
}
This is more or less what I did :)
Ist there a way to get a list of the IDs of all registered custom thumbnails for the current post? This way it would be possible to code a filter that works dinamically for every project.
Thanks for your help!
El 31/05/2013, a las 19:48, Chris Scott notifications@github.com escribió:
secondary-image
Not easily, no. Probably the best way would be to create a blog option when you register the thumbnails that is an assoc array w/post type being the key and an array containing the ids used to register the thumbnail being the value. Then in the filter code you could grab that option's value by the current post type to get the ids and use them to get the post thumbnail id.
Hi!
Is there a way to exclude the custom post thumbnails from the post gallery?
Thanks!