0

I'm trying to let users post a video on one our sites with text beneath it. Is there a way display the YouTube thumbnail image as a user's post thumbnail.

Example:

I post a YouTube video on the site: IMAGE LINK

Using HTML/PHP I pull in the posts on to my website using the below code:

<?php
    $posts = get_posts('cat=3');
    foreach ($posts as $post) : setup_postdata( $post );
?>
        <?php the_date(); echo "<br />"; ?>
        <?php the_title(); ?>
    <?php endforeach; ?>

I want to load the image/video and then the title of the post. Not the date or any other content. How can this be done?

Then how can I make that thumbnail a link to go to the actual post?

Matt
  • 1,017
  • 2
  • 11
  • 27
John Ayers
  • 509
  • 1
  • 11
  • 33
  • is your question related to `user posting info into wordpress via front-end?` or `adding a new field in wordpress admin post page for thumbnail and then displaying it front-end` or both? sounds like a job for a hired developer. – vico Aug 05 '14 at 20:05
  • neither really im looking for a way to get the video or video image from the youtube video to use as a post tumbnail. – John Ayers Aug 05 '14 at 20:10
  • without it being automatic then read the answer below, and copy a link into your featured image, if you want this to be automatic you need to add a special custom field and a hook that triggers on update to - read the custom field and then strip and append it to the correct format from a utube link to a utube thumb link and update as the feature image of the post. – vico Aug 05 '14 at 20:22

2 Answers2

4

The above answer got me to this part. I figured Id share my corrected code.

<?php
    $posts = get_posts('cat=3');
    foreach ($posts as $post) : setup_postdata( $post ); 
?>
        <img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID, 'video', true); ?>/0.jpg" alt="<?php the_title(); ?>" width="200" height="150">
        <br />
        <?php the_title(); ?>    
    <?php endforeach; ?>
John Ayers
  • 509
  • 1
  • 11
  • 33
1

You could grab the video id by using a custom field and place it inside the Video Thumbnail URL to get the video thumbnail.

Community
  • 1
  • 1
Jared Dunham
  • 1,467
  • 2
  • 17
  • 29
  • Wow. Thank you. That was a great idea and worked perfectly. Quite easy as well. Im gonna mark this as the answer but ill add my code with it working below. – John Ayers Aug 05 '14 at 20:24