• Resolved Sutherland Boswell

    (@sutherlandboswell)


    Hey guys,

    I’ve been getting to know WordPress pretty well for about a year using it to post daily videos and news. I’ve built my own template and found this function here to grab the first image of a post

    // Get URL of first image in a post
    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    
    // no image found display default image instead
    if(empty($first_img)){
    $first_img = "DEFAULT-IMAGE";
    }
    return $first_img;
    }

    Well, I started using JR embed to give me flexibility with changing embed sizes in future layouts, and I decided I need to find a way to get the YouTube video ID from the post so I can have a loop with thumbnails of the videos… Is there a way to create a new function similar to the one for images so I can do this?

    I have very little experience in PHP, and was hoping a nice soul might help me figure out how to create a function to do this, or to have a better way of managing the video posts within WordPress. I don’t want to use a custom field in the post because other people with less knowledge post updates.
    Thanks in advance, I love the WordPress community!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Sutherland Boswell

    (@sutherlandboswell)

    Well, 6 months later and I’ve learned enough to make my own plugin to solve this problem. Video Thumbnails is a plugin that creates a simple function that can be used in your loop to automatically retrieve a thumbnail for embedded videos.

    <?php video_thumbnail(); ?>

    Sutherland!

    I am experiencing your pain man… I am a videographer and the vast amount of the work that i want to showcase lies not on YouTube or Vimeo. It’s on Blip.TV and Ustream! So I need a plugin that can embed those for me. I’ve tried just about all the plugins that give that functionality, but can’t seem to find anything that will also work with Blip or Ustream. And even if it did, I also want to be able to put the video in a modal like lightbox and just use a thumbnail in a gallery… Well I’ve figured out one half of the solution…

    oEmbed. Ever heard of it? It’s a developing standard that a lot of rich media providers are starting to support for getting things like video/audio/pictures/documents into webpages, without content creators like us having to either drop in the <embed> or <object> html or having to have a ton of plugins that only work for one thing and not another…

    WordPress already has something called the [embed] tag where you can put a URL for YouTube, Vimeo, and a few others and it’ll auto embed it in the post. Well a startup called embed.ly has a plug in that will do that for 155 (and growing everyday) providers. Here’s the big thing though… Their API will PULL THE THUMBNAIL AUTOMATICALLY if requested. Test their api at http://api.embedly.com with any URL you can think of for YouTube, Vimeo, Facebook, Daily Motion, CNN… You’ll see what I mean. They have a WORDPRESS PLUGIN that I use in the posting section AND the comments area of my blogs. All you have to do is just leave a valid URL to a content provider on it’s own line, and it auto expands… Even in the comments area (useful for when people want to leave video comments

    It gets better. Also it seems someone already took a step in the right direction by building a thumbnailer API based on Embed.ly
    http://thumbnailer.nxccs.com/
    Thumbnailer is a free service which finds or generates thumbnails from anything, from images, to webpages, to YouTube videos.
    Thumbnailer is also free software, released under the GNU Affero General Public Licence. If you’re interested in the source code of this service, it’s available on Github.
    we can use this API to just pull in thumbs for everything, and use the raw embed.ly plugin to embed media.

    If this appeals to you, let me know. I’m trying to get some people on-board to help me make and test the plugin…

    Tara Rotten

    (@tara-rotten)

    Sutherland

    will you post the code you used to get the thumbnails working in

    // Get URL of first image in a post
    function catch_that_image() {
    global $post, $posts;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    
    // no image found display default image instead
    if(empty($first_img)){
    $first_img = "DEFAULT-IMAGE";
    }
    return $first_img;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Grabbing YouTube ID from post’ is closed to new replies.