Retrieving thumbnail images

Support MB Group Retrieving thumbnail images

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1726
    jonwatson87jonwatson87
    Participant

    Hey guys!

    I'm using file_input to upload an image to a group, but want to return the thumbnail on the front end.

    Is there any way to add image args when calling the image - something like "size = thumbnail"?

    $speakergroup = rwmb_meta( 'cf_speakers' );
    
    foreach ( $speakergroup as $speakerdata ) {
    
    echo '<a href="' . $speakerdata['cf_speakerurl'] . '" target=_blank><img src="' . $speakerdata['cf_speakerpic'] . '" class="circle wp-post-image"></a>';
    
    }
    #1730
    Anh TranAnh Tran
    Keymaster

    Hi,

    The file_input field store the URL of the image in the post meta, so if you use rwmb_meta() function, you will get the URL of the file.

    In case you want to use more sizes of the file, WordPress has a helper function to retrieve attachment ID from the URL attachment_url_to_postid(). The sample code looks like this:

    $speakergroup = rwmb_meta( 'cf_speakers' );
    foreach ( $speakergroup as $speakerdata ) {
      $attachment_id = attachment_url_to_postid( $speakerdata['cf_speakerpic'] );
      list( $src ) = wp_get_attachment_image_src( $attachment_id, 'thumbnail' );
      echo '<a href="' . $speakerdata['cf_speakerurl'] . '" target=_blank><img src="' . $src . '" class="circle wp-post-image"></a>';
    }
    #1734
    jonwatson87jonwatson87
    Participant

    Awesome! Just what I was looking for! You're a star! 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Retrieving thumbnail images’ is closed to new replies.