Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter dadvan

    (@dadvan)

    Anybody???

    Thread Starter dadvan

    (@dadvan)

    Anybody?

    Let me know if this doesn’t work for you.

    // Check for Plugin
    if (class_exists('MultiPostThumbnails')) {
    
    	// Set Thumbnail
    	$thumb = MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'preview-image');
    
    	// Thumbnail exist? Else show Not Found
    	if ($thumb) : echo $thumb; else : echo '<img src="url/to/default/image.jpg">'; endif;
    
    	// Plugin not found.
    	} else {
    
    		echo "MultiPostThumbnails Not Found.";
    }
    Thread Starter dadvan

    (@dadvan)

    Thanks Barryp! Something is not quite right here it is putting the fallback image on top of the Multipost Thumbnail:

    <?php // Check for Plugin
                  if (class_exists('MultiPostThumbnails')) {
    
                    // Set Thumbnail
                    $thumb = MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');
    
                    // Thumbnail exist? Else show Not Found
                    if ($thumb) : echo $thumb; else :?><img src="/images/icon.png" alt="<?php the_title(); ?>" /><?php ; endif;
    
                    // Plugin not found.
                  } else { ?>
    <img src="/images/icon.png" alt="<?php the_title(); ?>" />
                 <? }?>

    Just noticed this. Give me a few.

    Sorry for the delay. After looking through the plugin code, there is a has_post_thumbnail option. I came up with this that I’m sure could be written better, I’m still learning.

    // Check for Plugin
                  if (class_exists('MultiPostThumbnails')) {
    
                    // Set Thumbnail
                    $thumb = MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'preview-image');
                    $has_thumb = MultiPostThumbnails::has_post_thumbnail(get_post_type(), 'preview-image', strval(get_the_ID()));
    
                    // Thumbnail exist? Else show Not Found
                    if ($has_thumb) : echo $thumb; else : echo '<img src="'. get_bloginfo('template_directory') . '/img/default_thumb.jpg" />'; endif;
    
                    // Plugin not found.
                  } else {
    
                    echo "MultiPostThumbnails Not Found.";
    
                  }

    Barryp. This works a treat.

    Thanks!

    Thread Starter dadvan

    (@dadvan)

    Works, Thanks barryp!

    Sweet!! Glad it works for ya.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conditional Default Image’ is closed to new replies.