WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] auto generate thumbnail from video by scanning whole post - lost plug-in (10 posts)

  1. flint_and_tinder
    Member
    Posted 2 years ago #

    Hopefully someone can help here.

    Recently whilst building a theme for a client I added a plug-in to WordPress that automatically created a featured image (or thumbnail) for a video that was added to a 'project' custom post type. Unfortunately the client wanted to add their own thumbnails so I scrapped this feature.

    However now I need to recreate it and can't find the plug-in I used before. I have obviously found the video thumbnails plug-in here http://wordpress.org/extend/plugins/video-thumbnails/
    but I don't think this is the same plug-in for 2 reasons:

    a) When I install video thumbnails now, it adds a meta box above the featured image box which I am certain was not there before.

    b) In both the original theme and my recreation I used/am using custom fields to enter the Vimeo ID. This custom field data is the retrieved and added to the rest of the embed code within the page template. For example:

    <?php if( $project_item = get_post_meta($post->ID, 'vimeo_id', true) ): ?>
     <iframe src="http://player.vimeo.com/video/<?php echo $project_item; ?>?title=0&byline=0&portrait=0" width="508" height="286" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>

    It seems that the video thumbnails plug-in only reads the body content and not the custom fields and as a result the plug-in isn't generating or recognising any thumbnails within the post. I'm pretty certain that the original plug-in scanned the whole post. I've tried changing the Video Thumbnail plug-in code using the instructions in this link - http://wordpress.org/support/topic/plugin-video-thumbnails-cant-find-youtube-thumbnails - to check the 'Vimeo ID' custom field but I still get error messages both in Settings>Video Thumbnails and on the actual custom post type edit screen stating that no thumbnails can be found. I guess this is because only the ID is actually placed in the custom field.

    For the life of me I cannot recreate what I did before and it's sending me crazy. Does anyone out there have any idea of the plug-in I'm describing? Or any other plug-in that will work in the same way?

    Many thanks,
    Adam.

  2. Sutherland Boswell
    Member
    Posted 2 years ago #

    Hey Adam,

    I think you were really close to getting it working when you tried the change you mentioned. Like you mentioned, since the field only has the Vimeo ID you need to make one more small change. Instead of changing it to this:

    // Gets the post's content
    $video_key = 'vimeo_id';
    $markup = get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    Try changing it to this:

    // Gets the post's content
    $video_key = 'vimeo_id';
    $markup = 'http://vimeo.com/'.get_post_meta($post_id, $video_key, true);
    $new_thumbnail = null;

    Now the plugin should know it's from Vimeo.

  3. flint_and_tinder
    Member
    Posted 2 years ago #

    Perfect! Thank you so much, it works a charm.

    I do have a further question though. Ideally what I'm trying to set up is an action that checks to see if there is a value entered into the vimeo_id field and if not, then use a value entered into a youtube_id field.

    In the original template, I had this:

    <?php if( $project_item = get_post_meta($post->ID, 'vimeo_id', true) ): ?>
    <iframe src="http://player.vimeo.com/video/<?php echo $project_item; ?>?title=0&byline=0&portrait=0" width="508" height="286" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>
    <?php else: ?>
     <iframe width="508" height="286" src="http://www.youtube.com/embed/<?php echo get_post_meta($post->ID, 'youtube_id', true);?>" frameborder="0" allowfullscreen></iframe>
    <?php endif; ?>

    Do you have any idea how this would work with your plug-in? Would I need to add something similar to the code you've provided for the youtube_id field as well? If so, if you could point out where I'd be grateful and am more than happy to pay you for your time.

  4. flint_and_tinder
    Member
    Posted 2 years ago #

    Looking at the other other thread again, I'm thinking something like this would work:

    // gets custom field data
    $vimeoid = get_post_meta($post_id, 'vimeo_id', true);
    if($vimeoid) {
    	$markup = 'http://vimeo.com/'.get_post_meta($post_id, $vimeoid, true);
    } else {
    $youtubeid = get_post_meta($post_id, 'youtube_id', true);
    if($youtubeid) {
    	$markup = 'http://youtu.be/'.get_post_meta($post_id, $youtubeid, true);
    }
    $new_thumbnail = null;

    Unfortunately it doesn't. Does anyone know what I'm doing wrong?

  5. flint_and_tinder
    Member
    Posted 2 years ago #

    Adding in another } satisfies the WordPress system but not the plug-in. Code that isn't woking currently looks like this:

    // gets custom field data
    $vimeoid = get_post_meta($post_id, 'vimeo_id', true);
    if($vimeoid) {
    	$markup = 'http://vimeo.com/'.get_post_meta($post_id, $vimeoid, true);
    } else {
    $youtubeid = get_post_meta($post_id, 'youtube_id', true);
    if($youtubeid) {
    	$markup = 'http://youtu.be/'.get_post_meta($post_id, $youtubeid, true);
    }
    }
    $new_thumbnail = null;
  6. flint_and_tinder
    Member
    Posted 2 years ago #

    Does anyone have any idea on how I can get the Video Thumbnails plug-in to search 2 custom post fields as described above? I am more than happy to pay someone for their time and expertise.

  7. Sutherland Boswell
    Member
    Posted 2 years ago #

    I think you're pretty close, try changing 'http://youtu.be/' to 'http://www.youtube.com/watch?v='

    I don't think it currently checks for youtu.be links, but it's something I should add. PS - Donations are always welcome!

  8. flint_and_tinder
    Member
    Posted 2 years ago #

    Hi Sutherland,

    Thanks a lot for your input. Unfortunately that slight change of code hasn't fixed it. I still get the 'We didn't find a video thumbnail for this post. (be sure you have saved changes first)' message for projects that have a youtube_id rather than a vimeo_id.

  9. Sutherland Boswell
    Member
    Posted 2 years ago #

    Ah, I just realized you're using get_post_meta() twice for each source and asking for the wrong field the second time, try this.

    // gets custom field data
    $vimeoid = get_post_meta($post_id, 'vimeo_id', true);
    if($vimeoid) {
    	$markup = 'http://vimeo.com/'.$vimeoid;
    } else {
    $youtubeid = get_post_meta($post_id, 'youtube_id', true);
    if($youtubeid) {
    	$markup = 'http://www.youtube.com/watch?v='.$youtubeid;
    }
    }
    $new_thumbnail = null;
  10. flint_and_tinder
    Member
    Posted 2 years ago #

    Amazing, thank you Sutherland. It works a treat. Now if I can just get a few other bits and bobs working I should be in a position to give you a donation.

Topic Closed

This topic has been closed to new replies.

About this Topic