• jalacom

    (@jalacom)


    In the portfolio theme I’m creating, I’m utilizing a plugin (Multiple Post Thumbnails) to add a second feature image to the top of my portfolio posts. I would like to add this script adaptive-backgrounds.js to allow the background (when visible) to change color based on a sample from that second feature image I’m including in a div with an id of “folio-image”. Here’s a post from the theme in progress: sample post

    The problem
    The script requires an img attribute of data-adaptive-background=’1′
    I can’t seem to include the attribute onto the image. I realize that the_post_thumbnail(); accepts two parameters one of which is an array for adding in attributes. Apparently though, I am doing it wrong. I’m still learning so not sure of the correct syntax for everything. Currently I have the Mutliple Post Thumbnail plugin activated and the following code is placed in my functions.php file:

    if (class_exists('MultiPostThumbnails')) {
        new MultiPostThumbnails(
            array(
                'label' => 'Portfolio Image',
                'id' => 'folio-image',
                'post_type' => 'post'
            )
        );
    }

    On my single.php file I’ve included:

    <div id="folio-image">
    <?php if (class_exists('MultiPostThumbnails')) :
        MultiPostThumbnails::the_post_thumbnail(
            get_post_type(),
            'folio-image'
    	);
    endif; ?>
    </div>

    The image displays as needed. But I’m not sure how to include the needed attribute. This link on Stackoverflow says to include it like so: the_post_thumbnail( 'folio-image', array( 'data-adaptive-background' => 1 ) ); I can’t seem to figure out where to place that having tried multiple times.

    I feel like the answer seems to be in the plugin documentation here. Where it says to use the wp_get_attachment_image() argument for adding attributes. But after trying several approaches and getting not much more than a few parse errors and/or no change to the image at all, I haven’t been successful in including the needed atttribute.

    Thanks in advance for any help you might have. I always appreciate the WP community’s willingness to help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jalacom

    (@jalacom)

    hopefully I’m not over complicating my question.
    Let me know if you can help me out.

    Thread Starter jalacom

    (@jalacom)

    No luck so far. Still can’t add the necessary img attribute for the js file to function.
    Could use some help. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using MultiPostThumbnails Plugin, trouble adding an IMG Attribute for .js use’ is closed to new replies.