Support » Plugins » Hacks » Attach custom field thumbnail using php

Viewing 3 replies - 1 through 3 (of 3 total)
  • knolan2

    (@knolan2)

    I changed part of the code to:

    <?php
      /* Set variables and create if stament */
      $video_thumbnail = get_post_meta($post->ID, 'Video Thumbnail');
      $videosite = get_post_meta($post->ID, 'Video Site', single);
      $videoid = get_post_meta($post->ID, "Video ID", single);
      if ($videosite == vimeo) {
      echo '<iframe src="http://player.vimeo.com/video/'.$videoid.'" width="300" height="200" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
      } else if ($videosite == youtube) {
      echo '<a class="fancybox"  title="" href="http://www.youtube.com/watch?v='.$videoid.'?fs=1&autoplay=1"><img src="' .$video_thumbnail. '" /></a>';
      } else {
      echo 'Please Select Video Site Via the CMS';
      }
    ?>

    and now I am getting the img src= array

    Moderator bcworkz

    (@bcworkz)

    Hello again knolan2,

    You need to pass true as a third parameter to get_post_meta() so that it returns a string instead of an array.
    $video_thumbnail = get_post_meta( $post->ID, 'Video Thumbnail', true );

    knolan2

    (@knolan2)

    I tried it wasn’t working. I changed the code to use the feature image as the thumbnail. If anyone wants to know what I did:

    <?php
                    /* Set variables and create if stament */
    				$thumb_id = get_post_thumbnail_id();
    				$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
    				$thumb_url = $thumb_url_array[0];
    				$videosite = get_post_meta($post->ID, 'Video Site', single);
    				$videoid = get_post_meta($post->ID, "Video ID", single);
    				if ($videosite == vimeo) {
      				echo '<a class="fancybox" title="" href="http://www.vimeo.com/'.$videoid.'"><span class="tv-title">'. get_the_title() .'</span><img src="' . $thumb_url . '" /></a>';
    				} else if ($videosite == youtube) {
      				echo '<a class="fancybox" title="" href="http://www.youtube.com/watch?v='.$videoid.'?fs=1&autoplay=1"><span class="tv-title">'. get_the_title() .'</span><img src="' . $thumb_url . '" /></a>';
    				} else {
      				echo 'Please Select Video Site Via the CMS';
    				}
    			?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Attach custom field thumbnail using php’ is closed to new replies.