I have a basic blog style site with recent posts listed on the homepage. The problem I was having is videos would not show up on the homepage because you can't assign a video as a featured image. I did not want to use thumbnail images for videos. I want users to be able to play videos without clicking through to the post.
So I found some code that has done an good job of doing just that. If a video is embed in a post it will automatically post the video where the featured image would usually be.
But now I have ran into 2 problems with the code...
1) If I have more than one video embed in a post it will not show any video and only show the post title on homepage.
2) If I try to add a featured image as a thumbnail of the video for my "recent posts", the code will show the featured image above the video.
I need to be able to assign a featured image in the post that will show as post thumbnail only on "recent posts" section. I don't want the thumbnail to show above the video on the homepage or above the video within the post.
Then secondly I need the code to allow more than one video in a post and make it select the first video in the post as the video that gets displayed on the homepage.
Here is the code from my features.php.
/** Add Video Homepage */
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="630" height="350" src="';
echo $first_vid;
echo '" frameborder="0" allowfullscreen></iframe>';
}
}
And here is the code I place in the loop for my posts.
<?php echo catch_video() ?>
Project Details:
Wordpress version 3.4.1
WPZOOM Morning Theme
Total Budget $38
Project to be completed in 2 days
I have several years experience working with Wordpress. I can give you a quality design/development in little time without taking away from the quality of the work.
I am a professional who will pay attention to details, give you a great experience, good communication and on time!
Let me know if you have any questions.
Thanks,
Robert