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

Usage with Total WordPress Theme (guide - not an issue) #84

Closed wpexplorer closed 8 years ago

wpexplorer commented 8 years ago

Several customers of our Total theme have asked how they can display their secondary image on the single posts instead of the default featured image. So here is a little snippet for those wondering:

function myprefix_blog_entry_thumbnail_args( $args ) {

    // Your secondary image ID
    $secondary_image_id = 'secondary-image'; // NOTE: tweak this to match your ID
    $secondary_image_meta_key = get_post_type() .'_'. $secondary_image_id .'_thumbnail_id';

    // Get your second image and if it exists update the attachment param
    // Note: Only if attachments is currently empty to prevent issues with sliders
    if ( empty( $args['attachment'] )
        && $secondary_image = get_post_meta( get_the_ID(), $secondary_image_meta_key, true )
    ) {
        $args['attachment'] = $secondary_image;
    }

    // Return args
    return $args;

}
add_filter( 'wpex_blog_entry_thumbnail_args', 'myprefix_blog_entry_thumbnail_args' );

ps: Great plugin guys!