WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Multiple 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.

See the full documentation for more: http://voceconnect.github.io/multi-post-thumbnails/

I'm trying to upgrade to a new versions of WordPress and get an error about `MultiPostThumbnails`

This is caused by using the example in previous readmes that didn't do a check for the MultiPostThumbnails class existing first. This has been corrected in the Installation section.

How do I register the same thumbnail for multiple post types?

You can loop through an array of the post types:

        if (class_exists('MultiPostThumbnails')) {
            $types = array('post', 'page', 'my_post_type');
            foreach($types as $type) {
                new MultiPostThumbnails(array(
                    'label' => 'Secondary Image',
                    'id' => 'secondary-image',
                    'post_type' => $type
                    )
                );
            }
        }

How do I use a custom thumbnail size in my theme?

After you have registered a new post thumbnail, register a new image size for it. e.g if your post thumbnail id is secondary-image and it is for a post, it probably makes sense to use something like:

    add_image_size('post-secondary-image-thumbnail', 250, 150);

This will register a new image size of 250x150 px. Then, when you display the thumbnail in your theme, update the call to MultiPostThumbnails::the_post_thumbnail() to pass in the image size:

    MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image', NULL,  'post-secondary-image-thumbnail');

You can register multiple image sizes for a given thumbnail if desired.

How can I get the thumbnail without automatically echoing it?

Use MultiPostThumbnails::get_the_post_thumbnail() in place of MultiPostThumbnails::the_post_thumbnail().

How do I get just the URL of a thumbnail without the wrapping HTML?

Use MultiPostThumbnails::get_post_thumbnail_url() passing in the following arguments:

  • $post_type - the post type the thumbnail was registered for
  • $id - the ID used to register the thumbnail (not the post ID)
  • $post_id - optional and only needs to be passed in when outside the loop but should be passed in if available when called

For example, for a thumbnail registered with an id of secondary-image and post_type of post the following would retrieve the thumbnail URL:

    MultiPostThumbnails::get_post_thumbnail_url(get_post_type(), 'secondary-image');

When I use the sample code the thumbnail doesn't show up. What's wrong?

  • Make sure you are using the same ID you registered the thumbnail with as the second argument to MultiPostThumbnails::the_post_thumbnail().
  • If you are trying to get the thumbnail outside of the loop or a single template, you will need to replace get_post_type() with the post type you are trying to get the thumbnail for. This is common when trying to use the code in headers/footers/sidebars.

I see the meta box in the admin when editing a post but when I click on 'Set as [label] image' in the media manager, nothing happens and I get a JavaScript console error

If you are using a symlink to include the plugin directory in your project, the admin js file will not load and cause this. Unfortunately, the solution is to not use symlinks due to the behavior of PHP's __FILE__

= Is there a way to show the post meta where the thumbnail IDs are stored in the Custom Fields metabox?

Since version 1.5 these are hidden by default. To unhide them, add add_filter('mpt_unprotect_meta', '__return_true'); to your theme's functions.php

Is there a github repo? I love me some submodules!

Yes. https://github.com/voceconnect/multi-post-thumbnails

Pancakes or waffles?

Pancakes.

Requires: 2.9.2 or higher
Compatible up to: 3.9.1
Last Updated: 2014-6-27
Downloads: 98,898

Ratings

4 stars
4.7 out of 5 stars

Support

1 of 7 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

4 people say it works.
0 people say it's broken.

0,1,0
100,3,3 71,7,5
75,8,6 100,7,7
100,6,6
100,3,3
100,1,1 100,1,1
50,8,4 83,6,5
100,1,1
100,3,3
100,3,3
73,11,8 80,5,4 100,1,1 100,4,4
57,7,4
100,12,12 100,8,8 100,1,1
50,2,1 100,3,3
100,3,3
88,8,7 80,5,4
100,5,5 100,1,1
80,5,4 100,4,4 100,1,1
100,4,4 83,6,5 80,5,4
100,5,5
100,2,2
100,5,5
100,1,1
67,6,4
100,1,1
100,1,1
100,2,2
100,4,4