Presenting videos using WordPress
Leave a response | Trackback |
Tags: custom fields, WordPress
And without using a plugin.
I thought of creating this post when I was on my way home from the recently concluded WordCamp Philippines. There was a woman who was in Karla Redor’s talk who asked on how she can host the video in her own blog and use WordPress to file it for her. She can use a plugin that will let her upload the videos in her blog or do it the “harder” way. Something that I’m very fond of doing.
Seriously, I’m the type of person who would only resort to using plugins if:
- I’m lazy at the time to think of another way without using a plugin
- My head is aching and I’m getting frustrated because it just won’t follow what I’m telling it.
The reason is because I am not a developer and it’s really hard to be dependent on a plugin specially if that plugin is what’s keeping your blog alive. Also, if the developer of the plugin suddenly stops supporting the plugin and no one else is willing to take it up from there. What’s worse is if it’s not compatible with the newer version of WordPress. Then I will be lost.
So anyway, on to the “how”.
- Convert you video to a
.swffile, you can use Hey!Watch, it has a fee though but considering how it will make your life easier, I think it’s worth it. Besides it will convert a video for $0.10 so I don’t think that’s too much. - Next in your code (you’d want to add this in your
single.phppage), call for the video custom field (which you’ll be adding later on). Note that this should be within the loop. Also, note that the snippet is taken from a WordPress support forum and changed to suit the topic.<?php $video = get_post_meta($post->ID, 'video', true); ?> <?php if (!empty($video)) {;?> <object type="application/x-shockwave-flash" data="<?php echo $video; ?>" width="400" height="300"> <param name="movie" value="<?php echo $video; ?>" /> </object> <?php }; ?>What does this mean? The first line sets the
$videovariable to the value of thevideokey (of the custom field). Next it checks if thevideohas a value attached to it (in that particular post). If it does, it inserts the value in thedataandvalueproperties ofobjectandparam. If thevideodoesn’t have any values then it won’t display anything.This way, it saves you the time to copy and paste the entire code for the video. Now if you want the lazier way, you will have to adhere to some restrictions. For example, you can set the value of
dataandvalueto:<?php bloginfo(’URL’) ?>/videos/<?php echo $video; ?>
This means that you will only be able to upload videos within the videos folder within your root. That way, you’ll only put the filename of the video in the custom field value.
- Once you’ve uploaded your video to your server (within the specified folder of course), go to the admin panel of your blog and then create a post (or a page) in your custom fields area, do what’s illustrated in the image below:
As you can see, I decided that I want to have another folder within my videos folder. My videos will be categorized according to shows, so the value of my video key is unang_hirit/episode_100.swf. Once published, the post’s HTML will appear like this:
<object type="application/x-shockwave-flash" data="http://domain.com/videos/unang_hirit/episode_100.swf" width="400" height="300"> <param name="movie" value="http://domain.com/videos/unang_hirit/episode_100.swf" /> </object>
Featured Video
If for some reason, you want to create a section that is called the “Featured Video” section on your sidebar, you can call it by using the following lines of code:
<?php query_posts('category_name=Featured Videos&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php $video = get_post_meta($post->ID, 'video', true); ?>
<?php if (!empty($video)) {;?>
<object type="application/x-shockwave-flash" data="<?php echo $video; ?>" width="400" height="300">
<param name="movie" value="<?php echo $video; ?>" />
</object>
<?php }; ?>
<?php endwhile(); ?>
If you’d notice, we recycled the code from above. The only difference is the query_posts tag before the loop. What the query_posts tag does is that it takes a single, recently added post (showposts=1) from a category called “Featured Videos”. And it’s the same business as what was discussed above.
Further reading:


This tutorial will definitely come in handy to me in the future!
Glad it could be of any help hehe
Well whadya know, I found http://corp.kaltura.com/wordpress_video_plugin (this) today. I’m sure there are others like it.
My advice to corporations (especially media outfits) who want to use WordPress with videos is that they take a look at the existing video providers out there first, and be willing to pay for it especially if they want to maintain a large collection. Perhaps they can consult with the folks from Automattic, even, since I’m sure there are similar companies who needed the same requirements.
Yay! Ia, you just saved my arse, I need this for a new project
Pfft, these local media outfits are too stingy
I’m laughing at the way I “linked” to that site. I forgot I’m not on Plurk. Sheesh!
LOL di ko na nga pinansin eh hahaha