WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Post Thumbnails
[resolved] Retrieve secondary image url (16 posts)

  1. Brett Shumaker
    Member
    Posted 2 years ago #

    So, long story short...I'm using the 'Featured Image' on my custom post type to be the 'thumbnail' for the post and I would like it to link to my post's 'Secondary Image.' (A kind of hack for setting a custom cropped thumbnail.)

    Does this plugin offer a way to simply retrieve the url of the Secondary Image?

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

  2. publicradio
    Member
    Posted 2 years ago #

    This says it's resolved. How did you resolve it?

  3. Brett Shumaker
    Member
    Posted 2 years ago #

    It has been a little while since I figured this out but I accessed a function (get_post_thumbnail_url) located within the "MultiPostThumbnails" class in multi-post-thumbnails.php.

    I was using this in a custom post type and the following line was located within The Loop.

    $secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('POST-TYPE','secondary-image');

  4. publicradio
    Member
    Posted 2 years ago #

    Thanks for the quick reply. I don't think that function exists in that plugin. I know it does for WordPress, but not the plugin itself. Are you sure this is how you did it? It doesn't work for me.

  5. Brett Shumaker
    Member
    Posted 2 years ago #

    Well I remember, now, that the plugin author had given me a link to a build of the plugin that had not, and I guess still hasn't, been released.

    I'll mark this as unresolved again and maybe that will prompt the author to reply.

  6. Chris Scott
    Member
    Plugin Author

    Posted 2 years ago #

    This was likely due to some version issues. 1.0 was just released so an update should get it.

  7. mikizzi
    Member
    Posted 1 year ago #

    Is there anyway retrive URL path only from this function??? <?php
    echo MultiPostThumbnails::the_post_thumbnail('casestudy', 'image2'); ?>

    This below is what I want achieve URL path is missing from href

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('casestudy', 'image2')) : ?>
     <a href=""> <?php MultiPostThumbnails::the_post_thumbnail('casestudy', 'image2', NULL, 'post-image2-thumbnail'); ?></a>
       <?php endif; ?>

    Thanks in advance

  8. mikizzi
    Member
    Posted 1 year ago #

    `
    <?php if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('casestudy', 'image2')) : ?>
    <a class="lightbox" href="" > <?php MultiPostThumbnails::the_post_thumbnail('casestudy', 'image2', NULL, 'post-image2-thumbnail'); ?></a>
    <?php endif; ?>

  9. Chris Scott
    Member
    Plugin Author

    Posted 1 year ago #

    @mikizzi

    As noted above, the MultiPostThumbnails::get_post_thumbnail_url() function should do it. Likely MultiPostThumbnails::get_post_thumbnail_url('casestudy', 'image2') will work based on what you have above.

  10. mikizzi
    Member
    Posted 1 year ago #

    got it ! thanks for replying!!

  11. rocboy001
    Member
    Posted 1 year ago #

    Hey Chris,

    I'm trying to use the code about by mikizzi, but I am a little confused...

    <?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('product-item', 'primary-image')) : ?>
      <a href="#">
        <?php MultiPostThumbnails::get_post_thumbnail_url('product-item', 'primary-image'); ?>
      </a>
    <?php endif; ?>

    Is this correct? This is on an individual post page.

    Thanks!

  12. Scott
    Member
    Posted 1 year ago #

    How would I retrieve the url of a custom image size since get_post_thumbnail_url doesn't support image name?

  13. Scott
    Member
    Posted 1 year ago #

    I came up with this workaround for anyone interested.

    Note: In this example I used a foreach loop. It's definitely not required. But I needed multiple image URL.

    <?php
    	$slider_sizes = array(
    		"portfolio-slide-large",
    		"portfolio-slide-med",
    		"portfolio-slide-small"
    	);
    
    	foreach ($slider_sizes as $slider_size) {
    
    		$attachment_id = get_post_meta($post->ID, 'portfolio_secondary-image_thumbnail_id', true);
    
    		$url = wp_get_attachment_image_src( $attachment_id, $slider_size );
    
    		$slider_src[] = $url[0];
    	}
    ?>
  14. Chris Scott
    Member
    Plugin Author

    Posted 1 year ago #

    @scott you can pass the size in to MultiPostThumbnails::get_the_post_thumbnail() as the fourth arg. See the function signature:

    public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' , $link_to_original = false)

  15. charmedworks
    Member
    Posted 1 year ago #

    My secondary thumbnail is called main-image.

    I would like to return the URL of the image being used for the thumbnail to use to link to it from the thumbnail. I am not able to get get_post_thumbnail_url to return the URL.

    Here is what I have tried as a starting point, but it is returning an empty href="". Any help appreciated. I also posted this to another question which suggests there might be a slightly different way to do this, I am trying two different ways, so not trying to overpost.

    <?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::
     $secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('POST-TYPE','main-image');
    echo '<a href="' . $secondary_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox" >';
    the_post_thumbnail(get_post_type(), 'main-image',NULL,  'medium');
       echo '</a>';
    endif; ?>
  16. charmedworks
    Member
    Posted 1 year ago #

    Hi, I found this:

    http://wordpress.org/support/topic/plugin-multiple-post-thumbnails-llink-to-full-size-image-from-thumbnail?replies=14

    Which I had missed earlier, and used code modified from here to make my link to larger images work. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic