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

Trouble using with image size and attribute with a class in it #78

Closed immeasurablespectacle closed 8 years ago

immeasurablespectacle commented 8 years ago

I am trying to add a class to the post thumbnails but when I add the class it doesn't display the thumbnail. This also happens with the image size and I'm wondering if I'm doing something wrong. I have 2 post thumbnails ID "banner-image" and ID "right-small-image"

In the function.php file I have:

add_theme_support( 'post-thumbnails'  );
add_image_size('slider-background', '975', '345', true);
add_image_size('right-small', '250', '200');
add_image_size('wide-banner', '600', '200');

if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(
        array(
            'label' => 'Top Banner Image',
            'id' => 'banner-image',
            'post_type' => 'page'
        )
    );

    new MultiPostThumbnails(
        array(
            'label' => 'Top Right Small Image',
            'id' => 'right-small-image',
            'post_type' => 'page'
        )
    );
}

In the page itself I have the code to display the two post thumbnail types:

    <?php
        // If the page has a banner image display it here
         if (class_exists('MultiPostThumbnails')) :
            $attr = array("class" => "banner-feature-image");
            MultiPostThumbnails::the_post_thumbnail(
                get_post_type(),
                "banner-image",
                "wide-banner",
                $attr
            );
        endif; 
    ?>

    <?php
        // If the page has a small right image on the top, beneath the heading, display it here
         if (class_exists('MultiPostThumbnails')) :
            $attr = array("class" => "right-small-feature-image");
            MultiPostThumbnails::the_post_thumbnail(
                get_post_type(),
                "right-small-image",
                "right-small",
                $attr
            );
        endif; 
    ?>

Is there some sort of issue with my syntax? Or is there some sort of bug?

It works just fine when I exclude the image size and the $attr at the end. When I include either of these the image stops showing up in the page and html output.

Thank you for making this incredibly useful plugin and for your time and consideration.

chrisscott commented 8 years ago

You're missing the post_id as the 3rd parameter in the call to MultiPostThumbnails::the_post_thumbnail(). See the function declaration or the docs for more info.

immeasurablespectacle commented 8 years ago

That fixed it, thanks!