WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Post Thumbnails
[resolved] array add class not working (2 posts)

  1. justclint
    Member
    Posted 2 years ago #

    How can we add a class to our second image? The following does not seem to work:

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'sidebar-image')) :
            MultiPostThumbnails::the_post_thumbnail('page', 'sidebar-image', array('class' => 'class-name')); endif; ?>

    Thanks!

    http://wordpress.org/extend/plugins/multiple-post-thumbnails/

  2. justclint
    Member
    Posted 2 years ago #

    This seemed to do the trick:

    if (class_exists('MultiPostThumbnails')) {
              $image_name = "sidebar-image";
                    if (MultiPostThumbnails::has_post_thumbnail('page', $image_name)) {
                        $image_id = MultiPostThumbnails::get_post_thumbnail_id( 'page', $image_name, $post->ID );
                        $attr = array('class' => "border-1");
                        $image = wp_get_attachment_image( $image_id, 'sidebar-image', false, $attr );
                        echo $image;
                    }
            };

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic