WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Post Thumbnails
[resolved] Multiple Post Thumbnails: Setting ID and/or class on image tag (2 posts)

  1. slurve
    Member
    Posted 3 years ago #

    Has anyone been successful in setting a specific class and/or ID on an image tag generated by this plugin?

    Here's the code I'm using in functions.php:

    if (class_exists('MultiPostThumbnails')) {
        $types = array('post', 'page', 'home_steps');
        foreach($types as $type) {
    			$thumb = new MultiPostThumbnails(array(
    				'label' => 'Secondary Image',
    				'id' => 'secondary-image',
    				'post_type' => $type
    				)
    			);
        }
    	}

    And in my template:

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

    It seems to simply output an image with class="attachment-post-thumbnail". Would be great if it could be a specific class that I could use.

    Any ideas? Thanks in advance.

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

  2. slurve
    Member
    Posted 3 years ago #

    I ended up using this code in functions.php:

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

    And then this in my template:

    <?php echo MultiPostThumbnails::the_post_thumbnail('home_steps', 'secondary-image', NULL, 'secondary-image'); ?>

    This essentially creates a new thumbnail size of 416x325 with a class of 'attachment-secondary-image'.

    Tom

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic