Sometimes, when we use a premium theme, we have some spot that contain images (thumbnail), and some spot will used to show video from youtube. Sometimes, we want to make this spot automatically choose the best value for it. When the post is not a youtube video post, then the thumbnail will show, and it will show youtube video when this post contain a youtube embedded code inside it.
There are several ways to show automatic thumbnail, you can see my previous post here (using get the image plugins), and here (using functions). For the youtube thumbnail, you can use youtube thumbnailer. But in this case, we do not want to show youtube thumbnail, but we want to show the video it self, so it can be played on that page.
In this case, if you want to show youtube video everywhere (at your page), you need a custom fileds inside your post. A custom fileds with value of Youtube Video ID.
If you were using wprobot, you can create a customfield at your youtube campaign with :
Custom Fields Name : videocode
Custom Fileds Value : {video}
Lest try to modify our theme :
1. If you want to choose between thumbnail from custom field or automatic thumbnail
- <?php if( get_post_meta($post->ID, "image", true) ): ?>
-
- <img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" width="50" height="50" class="thumbnail">
-
- <?php else: ?>
-
- <img src="<?php echo get_image(); ?>" width="50" height="50" class="thumbnail">
-
- <?php endif; ?>
2. If you want to choose between youtube video or automatic thumbnail
- <?php if( get_post_meta($post->ID, "videocode", true) ): ?>
-
- <object width="560" height="349"><param name="movie" value="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, "videocode", $single = true); ?>?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, "videocode", $single = true); ?>?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="349"></embed></object>
-
- <?php else: ?>
-
- <img src="<?php echo get_image(); ?>" width="50" height="50" class="thumbnail">
-
- <?php endif; ?>
That’s it for today. I hope this tips could inspired everyone that read this post.




Facebook comments: