Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I crating custom wordpress themes for video related website, client can embed youtube video, in index.php only show thumbnail image and title of video then when click thumbnail it goes to single.php & show the video,

Plase any one help me, I try Video Thumbnails it not work me.

share|improve this question
add comment

1 Answer

To solve this:

1. Add custom meta to each post which take youtube url( name of custom meta in code youtube).

2. In index.php loop:

  while(have_posts()){

    the_post();

   //use [get_post_meta][3] to get youtube post meta
   $youtube_img = 'http://img.youtube.com/vi/'.substr( get_post_meta($post-ID,'youtube') ).'/0.jpg';

   //$youtube_img is your youtube video image url
   echo '<a href="'.get_permalink().'">';
   echo '<img src="'.$youtube_img.'" title="'.get_the_title().'" alt="youtube video image for'.get_the_title().'"/>';
   echo'</a>';
   }

3. In single.php loop (set iframe width as you design need)

<?php
while(have_posts()){
    the_post();

    //use [get_post_meta][3] to get youtube post meta
    $youtube_link = get_post_meta($post-ID,'youtube');   
    ?>    

    //$youtube_link is your youtube url
    <iframe width="328" height="233" src="<?php echo str_replace('watch?v=','embed/', $youtube_link); ?>" frameborder="0" allowfullscreen></iframe>'
    <?php
}
share|improve this answer
    
This my code all so not working <?php if (have_posts()) : while(have_posts()){ the_post(); //use [get_post_meta][3] to get youtube post meta $youtube_img = 'img.youtube.com/vi/'.substr( get_post_meta($post-ID,'youtube') ).'/0.jpg'; //$youtube_img is your youtube video image url echo '<a href="'get_permalink().'">'; echo '<img src="'.$youtube_img.'" title="'.get_the_title().'" alt="youtube video image for'.get_the_title().'"/>'; echo'</a>;' } <?php endwhile; endif; ?> –  Faiq Adam Jul 8 '13 at 18:09
    
their are some error in php code formatting in your code. Try this <?php if (have_posts()) : while(have_posts()){ the_post(); //use [get_post_meta][3] to get youtube post meta $youtube_img = 'http://img.youtube.com/vi/'.substr( get_post_meta($post-ID,'youtube') ).'/0.jpg'; //$youtube_img is your youtube video image url echo '<a href="'.get_permalink().'">'; echo '<img src="'.$youtube_img.'" title="'.get_the_title().'" alt="youtube video image for'.get_the_title().'"/>'; echo'</a>'; } endif; ?> –  Ravs Jul 10 '13 at 13:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.