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

Any way to output placeholder image if not set? #25

Closed guuthemes closed 10 years ago

guuthemes commented 10 years ago

Hi,

Have this currently -

<?php
                    // If the current page is a static page, post or CPT
                    if ( is_page() || is_single() || is_singular( 'portfolio' ) ) {
                        if (class_exists( 'MultiPostThumbnails' )) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'header-image', NULL, 'header-image-full', array('class' => "custom-header-image") ); endif;
                    // If the current page is your posts page
                    } else if ( is_home() ) {
                        if (class_exists( 'MultiPostThumbnails' )) : MultiPostThumbnails::the_post_thumbnail( 'page', 'header-image', get_option('page_for_posts'), 'header-image-full', array('class' => "custom-header-image") ); endif;
                    }
                    ?>

And was wondering if there was an option to show a placeholder image if the thumbnail had not been set?

I can achieve this via the usual route of - if ( has_post_thumbnail($post->ID) ){ .... else ......placeholder.img etc...

But cannot see how I could hook this into your code?

many thanks

chrisscott commented 10 years ago

You can use MultiPostThumbnails::has_post_thumbnail() the same way you would use the standard has_post_thumbnail() to check for it. Just pass in the same parameters you would to MultiPostThumbnails::the_post_thumbnail(). You could also use MultiPostThumbnails::get_post_thumbnail() which will return false if there isn't one to be more efficient.