1

I have spent time and figured out how to add Multiple Thumbnails to a custom post type in the wordpress admin for the custom post type, code and question below:

    if (class_exists('MultiPostThumbnails')) { // imports to post_type pages
            new MultiPostThumbnails(array('label' => '2nd Feature Image', 'id' => 'feature-image-2', 'post_type' => 'page', 'post_type' => 'landing_pages')); /* 'post_type' => 'landing_pages' adds support for landing pages CPT */
            new MultiPostThumbnails(array('label' => '3rd Feature Image', 'id' => 'feature-image-3', 'post_type' => 'page', 'post_type' => 'landing_pages'));
            new MultiPostThumbnails(array('label' => '4th Feature Image', 'id' => 'feature-image-4', 'post_type' => 'page', 'post_type' => 'landing_pages'));
            new MultiPostThumbnails(array('label' => '5th Feature Image', 'id' => 'feature-image-5', 'post_type' => 'page', 'post_type' => 'landing_pages'));
    };

* Does anyone know if there is a way to write an array or condense the code below so you dont have to list the post type twice:

    new MultiPostThumbnails(array('label' => '2nd Feature Image', 'id' => 'feature-image-2', 'post_type' => 'page', 'post_type' => 'landing_pages'));

Thanks.

1

1 Answer 1

1

All I apologize the code above was not completely working. I did research and found out how to condense the code for Multipostthumbnails so you can easily include the added thumbs for page, post and/or custom post types. Please let me know if you have a cleaner method.

    add_theme_support( 'post-thumbnails' );
    require_once('lib/multiple-post-thumbnails/multi-post-thumbnails.php'); /* Must be located directly under lib folder */
    // Define additional "post thumbnails". Relies on MultiPostThumbnails to work
    if (class_exists('MultiPostThumbnails')) { 

    $types = array('page', 'landing_pages' ); /* 'landing_pages' adds support for landing pages CPT,  'post' adds support for blog single pages */
    foreach($types as $type) {
    new MultiPostThumbnails(array('label' => '2nd Feature Image', 'id' => 'feature-image-2', 'post_type' => $type)); 
    new MultiPostThumbnails(array('label' => '3rd Feature Image', 'id' => 'feature-image-3', 'post_type' => $type));
    new MultiPostThumbnails(array('label' => '4th Feature Image', 'id' => 'feature-image-4', 'post_type' => $type));
    new MultiPostThumbnails(array('label' => '5th Feature Image', 'id' => 'feature-image-5', 'post_type' => $type));
    }

    };

Then in your page templates place this code where you wish the image to appear:

    if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('landing_pages', 'feature-image-2')) :
    MultiPostThumbnails::the_post_thumbnail('landing_pages', 'feature-image-2', NULL /*, 'add class name here' */ ); endif;

You can change where it says

    'landing_pages' 

to page or post if you are displaying on a page or a single page (blog post). The landing_pages is a custom post type I created.

Hope this helps and again if anyone has cleaner code please share.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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