Support » Plugins and Hacks » [Plugin: Multiple Post Thumbnails] Image not displaying

  • Resolved zeckdude

    (@zeckdude)


    I can get the Secondary Image Upload box to show up in the admin area, but I can’t manage to get the image to display on the page.

    This is the code I am using to try and make it display (From: http://wordpress.org/extend/plugins/multiple-post-thumbnails/installation/):

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

    I tried adding a random echo inside the if statement to see if it gets hit, but it doesn’t echo out, so i’m guessing somehow the condition is not being met?

    What am I missing?

Viewing 15 replies - 1 through 15 (of 19 total)
  • make sure that the post type matches up with the post type you declared when you register the post thumbnails.

    The author shows

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
        )
    );

    but then incorrectly tells you to put this in the template:

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

    if you registered it as post-type => page, then you’d have to use:

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); endif; ?>

    This got it all working for me.

    Don’t forget, this is really versatile! You could literally register ten or more post-thumbnails by giving them unique identifiers when registering them. Exciting stuff!

    Drew, thanks for the response. I appreciate the help!

    I changed the code as you suggested and it didn’t change anything unfortunately.

    Here is everything I have done with this plugin:

    I am using the twentyten theme as a parent them for a new theme I’m making.

    I activated the plugin.

    I put this in my functions.php file:

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );

    I put this in my page.php file:

    if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) :
                        echo 'This condition is met';
                        MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); endif;

    It said ‘post’ before, and I changed it to ‘page’ now, but that does not fix the problem.

    I uploaded an image, I can see the image uploads, it adds a new custom field with the name ‘post_secondary-image_thumbnail_id’ and the correct id number(i checked the database and it inserts the image location correctly).

    Sorry to hear that this didn’t work, but there is one difference between yours and mine. I changed the way the condition was formatted. This is a long shot, because everything you’ve done SHOULD make it work, but it hasn’t… Here is the exact code from my page.php:

    <?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) { ?>
    <div id="secondaryImage">
    	<?php MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); ?>
    </div>
    <?php } ?>

    And the div isn’t necessary, its for CSS so:

    <?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) {
      MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image');
    } ?>

    Zeckdude I had the same problem as you and I figured out how to fix it. Just omit the “$thumb =” part. You don’t have to assign the object to any variable. Put the following in functions.php:

    new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );

    Ha, nice.

    Really odd is that it works for me both ways…

    I had not placed my code inside the loop for the content for that particular page. Rookie Mistake!

    redacted

    worked with me when i entered the post id

    if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image',$post->ID)) :
        MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image', $post->ID, 'fifth-image');
        endif;

    worked with me when i entered the post id

    Yeah, it works for me too! Thank you, casper83! Nice solution.

    Yeah, it works for me too! Thank you, casper83! Nice solution.

    Yeah, it works for me too! Thank you, casper83! Nice solution.

    hello,

    where in functions.php do i put this code?

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );

    i tried putting it on the top of the page and at the bottom and i get errors.

    @themagiclaundry: This has to go between <?php and ?>

    so i was able to get the code inserted without errors now. when i goto posts, i see the secondary featured image. and i click “set as featured” or “set as secondary” but no matter what, no picture will appear on my page.

    the only way i can get an image to appear is if i use the “Featured” custom field. but that only allows me 1 picture per posts

    Have you also used the template code for e.g. single.php?

    The code in functions.php helps WordPress recognise that it is a second featured image. The template code asks WordPress to display it.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘[Plugin: Multiple Post Thumbnails] Image not displaying’ is closed to new replies.