Tech Hive

Blog on Wordpress, Design, Usability, Accessibility and Standards

  • Content
  • Sidebar
  • Footer
  • « WordCamp Philippines 2008
  • A Peek at WordPress 2.7 »

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:

  1. I’m lazy at the time to think of another way without using a plugin
  2. 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”.

  1. Convert you video to a .swf file, 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.
  2. Next in your code (you’d want to add this in your single.php page), 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 $video variable to the value of the video key (of the custom field). Next it checks if the video has a value attached to it (in that particular post). If it does, it inserts the value in the data and value properties of object and param. If the video doesn’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 data and value to:

    <?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.

  3. 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:

  • WordPress Codex: Using Custom Fields
  • A List Apart: Embedding Flash While Supporting Standards
  • WordPress Codex: Template Tags: query_posts

6 Responses to “Presenting videos using WordPress”

  1. Joni September 9, 2008 at 2:11 pm

    This tutorial will definitely come in handy to me in the future!

  2. Mae September 9, 2008 at 2:25 pm

    Glad it could be of any help hehe :D

  3. ia September 13, 2008 at 6:47 pm

    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.

  4. Mae September 13, 2008 at 8:32 pm

    Yay! Ia, you just saved my arse, I need this for a new project :D

    Pfft, these local media outfits are too stingy :(

  5. ia September 13, 2008 at 8:37 pm

    I’m laughing at the way I “linked” to that site. I forgot I’m not on Plurk. Sheesh!

  6. Mae September 13, 2008 at 8:50 pm

    LOL di ko na nga pinansin eh hahaha :P

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Pages

  • About the Author
  • Archives
  • Contact
  • Site Map
  • best 10 web hosting

Come in, we're hiring

Full-time and freelance job opportunities available at Authentic Jobs:

Post a job and reach web professionals everywhere.

Archives

  • May 2009
  • March 2009
  • November 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007

Categories

  • Accessibility
  • CSS Tips
  • Gmail
  • HTML
  • Online Finds
  • Online Tools
  • Review
  • Tutorial
  • Updates
  • Usability
  • WordPress
  • Wordpress Themes

Tech Hive is proudly powered by WordPress
Spartan by Mae Paulino, a Filipina Web Designer