Web Stuff
- Abban Dunne
- HeyStaks
- Howdie! Url Shortening With A Little Twist
- Music Shoots
- Mixtape
- Retailers Against Smuggling
Video Stuff
From the Blog
- Welcome to the BrightSky Studio
- Basic Camera Controls
- An Awesome New Option for Rural Internet Provision
- I Like Drisco – a charity single to help the people of Haiti
- Handy jQuery Overlay Info Panel
- Fun Friday: Jim’s Xmas Jingle
Latest Tweets
Follow us on Twitter »
Tags
AJAX Audio Beat Boxing Charlie Brooker Christmas Design Development Five Second Test Flowplayer Fun Friday gallery Google Wave Graffiti Grafitti Hero Worship JQuery jQuery Tools Labs Live Marketing Music MySQL NaNoWriMo National Novel Writing Month Omelette Performance php Programming Quick Tip Regulation SEO Skateboarding Streaming Conscious Team Building The Guardian Toaster Tuesday Tutorial Tutorial Twitter Usability Video Production Video Tutorial Wordpress WriteRoom Writing
Nov 30th
Manually Adding Flowplayer to a WordPress Theme
this tutorial teaches you a quick, and easily customisable way to get flowplayer working in any of your wordpress themes with videos uploaded through the wordpress admin panel.
People have been asking me how I got the excellent flash video player Flowplayer working in my WordPress themes on both BrightSky and Mixtape so I decided to do a post on it.
To do this tutorial I’m assuming that you are familiar with how WordPress themes are made and the how Template Hierarchy works.
First thing we need to do is download Flowplayer. When you unzip the file you will see it contains 2 swf files (one is the player and one is the control bar) and an example folder. Copy the 2 swf files and the flowplayer-3.1.4.min.js from the example folder into the folder of the WordPress theme you want to add it to.
Before we start coding lets upload a video and attach it to a post. Log into your WordPress admin panel and hit add post. Add a title and some body text then click the upload media link above the editor. Use this to upload your video and hit save. Don’t insert it into the post.
Now to the coding. First we need to attach the javascript file. Open the header.php file from your theme and copy the following line of code into it above the </head> tag:
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/flowplayer-3.1.4.min.js"></script>
Next we need to get it to play our video through the player. Open the single.php file in your WordPress theme and copy the following code into it:
<?php $videos =& get_children( 'post_type=attachment&post_mime_type=video&post_parent=' .$post->ID );
if(!empty($videos)){
foreach($videos as $video){
$src=$video->guid;
}
?>
<a href="<?php echo $src; ?>" style="display:block;width:520px;height:330px" id="player"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/placeholder.jpg" alt="video placeholder" /></a>
<!-- this will install flowplayer inside previous A- tag. -->
<script>
flowplayer("player", "<?php bloginfo('stylesheet_directory'); ?>/flowplayer-3.1.5.swf");
</script>
<?php } ?>
This code can be placed anywhere within The_Loop. What this is doing is utilising a function called get_children(). This function is taking the id of the current post and checking the database for children of it. We’re also passing the parameters post_type=attachment which ensures only attached media items are returned and post_mime_type=video which makes sure only attached videos are returned. The parameter post_parent is how it’s passing the id of the current post. All the information returned is saved as the variable $videos.
Next is an if statement. This is used to make sure that the player is only added to the page if there is a video attached to the post.
The $videos variable contains an array of the objects that are attached to the current post with the array keys set to the id of the attachment. As we don’t know this id we need to use a for loop to get access to the url of the video. This is what the next piece of code is doing.
Now we have a variable called $src which contains the url of our video. The a tag is where the video is going to be embedded. You can see that it has some inline style elements for changing the size of the player. The image tag is set to display an image called placeholder.jpg that you can create and place into the images folder in your theme. This image is displayed when the page loads first and the player is only loaded when the image is clicked.
The last piece of the code is the player script. This is what is actually embedding the player into the page. This is highly customisable and you can find loads of examples here.
Now go and check the post page on your blog to see your video. BAM! You now have Flowplayer working as part of your WordPress theme. You can see it working on this site right here.
Its worth noting that this code only displays the latest video attached to the post as I only needed one video to be attached per post. This code could be easily modified to embed multiple players. If you have any questions please leave a comment.
6 Responses to “Manually Adding Flowplayer to a WordPress Theme”
Leave a Reply













Mar 16th
PSD to WordPress says:
Hi Abban,
This was an awesome tutorial and I did get it implemented. Works like a charm.
I had one question though and thought maybe you could help me out with this.
I am building a real estate web site for a client and they want to display video for their properties and they love this option. The property videos are being called in a certain area. Now if their is no video attached there is just a blank space.
What they would like to do is display a image that says something like “Video for this property is not available at the moment” if there isnt an actual video attached to the post yet.
Using your code above how would I do something like that?
Any help would be and is greatly appreciated.
Mar 16th
Abban says:
I’d just add an else clause to the end of the code snippet so the bottom would look like:
< ?php }else{ ?>
Whatever you want to display.
< ?php } ?>
Mar 17th
PSD to WordPress says:
awesome worked like a charm…thank you very much – Keep up with the tutorials cuz Im lovin your site more and more
Mar 17th
Abban says:
Cheers dude! I have built up a load of little cool snippets to post but I made the rookie mistake of taking on much too much work and haven’t had any free time since Christmas.
I’m about to become much more free pretty soon so I expect to be posting more stuff on here.
Jul 2nd
pancho says:
HI, Abban,
Greate tutorial I almost done !
But, I decide to install the FV WordPress Plugin. If use this have to download the Flowplayer also? and attach the js script?
Much Thanx,
Pancho
Jul 2nd
Abban says:
Hey Pancho,
I would assume it does, I only tried it once and it didn’t have the functionality I needed. Thats the reason I added it manually.
I reckon give it a go though and if it does everything you need then go with it.