WordPress.org

Forums

Multiple Post Thumbnails
Using this plugin with custom post types (6 posts)

  1. devoninternational
    Member
    Posted 1 year ago #

    Is there a way to add support for multipostthumbs to a custom post type?

    When registering the custom post type I can get the single featured image to work by doing so with the 'thumbnail' below, is there a code like 'multipostthumbs' that I could add to the support string to get multiple post thumbs to display in the admin on the custom post type pages so I can add them to those pages on my website?

    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'post-thumbnails', 'genesis-seo', 'genesis-layouts' ) // By leaving out 'comments' there are no comments added to admin or allowed on these cpt pages

    http://wordpress.org/plugins/multiple-post-thumbnails/

  2. devoninternational
    Member
    Posted 1 year ago #

    ok I figured this out and wanted to share. You have to add the Custom Post Type in as well, see 'post-type' => 'landing pages

    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'));
    };
  3. devoninternational
    Member
    Posted 1 year ago #

    Forgot to mention to display the images I placed the below code in the template for the landing pages CPT:

    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;
    	if (class_exists('MultiPostThumbnails')
    	&& MultiPostThumbnails::has_post_thumbnail('landing_pages', 'feature-image-3')) :
    	MultiPostThumbnails::the_post_thumbnail('landing_pages', 'feature-image-3', NULL /*, 'add class name here' */ ); endif;

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

    'post_type' => 'page', 'post_type' => 'landing_pages'

  4. devoninternational
    Member
    Posted 1 year ago #

    I hope this helps someone out there, I wanted to make sure my last question was not hidden in my previous response:

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

  5. devoninternational
    Member
    Posted 1 year ago #

    My apologies, the code above after further testing was not working properly. Below is how I added support for pages, posts and CPT's and have fully tested and it is working correctly.

    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.

  6. kuwhankhan
    Member
    Posted 1 year ago #

    A lot of Thanks!! Works great on my CP.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multiple Post Thumbnails
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic