• I have seen a good bit of support with plugins or hacks that turn an embedded video into a thumbnail, but I was wondering if there was a way to have the post thumbnail be an actual video.

    Basically i have a site that is utilizing the Video Thumbnails plugin to pull a thumbnail from the video automatically & set it as the Featured Image.

    What I want is for my homepage to pull a featured image, unless its given a video (maybe custom_field), at which point I want it to display the actual video, instead of a thumbnail. Then, users can just watch the video right there in the home page without clicking through to the full post.

    Doable? PHP? Plugin?

Viewing 8 replies - 1 through 8 (of 8 total)
  • https://demo.shakenandstirredweb.com/shaken-grid/

    Shaken Grid has this feature plus it also does slideshows as a featured image.

    However, I am having a hard time dissecting how to do it manually.

    If does something like: post youtube embed code into post; takes a $variable of it; go to loop.php, if $variable = get_post_meta(…….) ; echo $variable

    I really want a plugin for this as well !!!@!!@!!

    this worked for me! it gets the first video (iframe) and it displays the player in the loop.

    this in function.php of my theme:
    function catch_video() {
    global $post, $posts;
    $first_vid = ”;
    ob_start();
    ob_end_clean();
    $output = preg_match_all(‘/<iframe.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
    $first_vid = $matches [1] [0];
    echo ‘<iframe width=”460″ height=”320″ src=”‘;
    echo $first_vid;
    echo ‘” frameborder=”0″ allowfullscreen></iframe>’;
    }

    and this goes in the loop:
    <?php echo catch_video() ?>

    this worked for me! it gets the first video (iframe) and it displays the player in the loop.

    this in function.php of my theme:

    function catch_video() {
      global $post, $posts;
      $first_vid = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_vid = $matches [1] [0];
      echo '<iframe width="460" height="320" src="';
      echo $first_vid;
      echo '" frameborder="0" allowfullscreen></iframe>';
    }

    and this goes in the loop:
    <?php echo catch_video() ?>

    this worked for me! it gets the first video (iframe) and it displays the player in the loop.

    this in function.php of my theme:

    function catch_video() {
      global $post, $posts;
      $first_vid = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_vid = $matches [1] [0];
      echo '<iframe width="460" height="320" src="';
      echo $first_vid;
      echo '" frameborder="0" allowfullscreen></iframe>';
    }

    and this goes in the loop:
    <?php echo catch_video() ?>

    this worked for me!

    function catch_video() {
      global $post, $posts;
      $first_vid = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_vid = $matches [1] [0];
      echo '<iframe width="450" height="310" src="';
      echo $first_vid;
      echo '" frameborder="0" allowfullscreen></iframe>';
    }

    I hate to ask a noob question, I can copy the code just fine into the functions, but what do you mean by

    and this goes in the loop:
    <?php echo catch_video() ?>

    hope this isn’t a waste of your time, I really am curious how to get this working

    16am that code worked great for me, thanks!

    rustbuckle: paste that echo catch_video() snippit in your template files where you want the video to display. In the loop means the part of template that renders your posts. It’s a larger discussion than I’ll have here, but for more info read: https://codex.www.ads-software.com/The_Loop

    you’ll find the loop in different template files depending on the theme you are using, but a good place to look is the front-page.php file. Your theme might call the loop here and then from within the loop call get_template_part( ‘content’ ). This indicates that the loop looks for the content.php template file and renders it over and over (looping), once for each post until you have displayed all of the posts.

    In my case I pasted echo catch_video() into a special template file that I’m using to render only my sticky posts. The sticky posts are using excerpt’s and featured images to display a quick version of the post on the front-page, and I wanted the video to display there. This special template file I’m using is called from the loop on front-page.php with this line: get_template_part( ‘content’, ‘issticky’ );

    Starting to make sense? If not, just open up some likely template files and paste the echo line in likely locations, one at a time. Eventually you’ll start to see where in the template files is corresponding to your web page in-browser.

    Oh, I also modified 16am’s code so that it would only display the iframe if there is a video in the post.

    function catch_video() {
      global $post, $posts;
      $first_vid = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_vid = $matches [1] [0];
    
      if ($output == '1') {
      echo '<iframe width="450" height="310" src="';
      echo $first_vid;
      echo '" frameborder="0" allowfullscreen></iframe>';
      }
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Video OR Featured Image’ is closed to new replies.