Awhile back I decided to start posting videos on my blog. Once I had a few videos up I began to rethink my approach. Ultimately I wanted to prevent videos from showing up where normal posts are displayed and instead display my most recent video in the sidebar.

To do this, I would need to:

Suppress all video posts from being displayed with other posts

Create an archive of all video posts

Resize and place my most recent video in the sidebar

The first step was pretty easy. I just created a new category called “Video Post” and assigned it to all of my video posts. This would become a fairly intuitive list of videos people could access at their will.

Next I wanted to remove all video posts from being displayed among other posts on the home page. However, I still wanted my videos to be displayed in RSS feeds as well as archives and search pages. To do this, I just modified the default WordPress query used to pull the most recent posts by placing the following code before “The Loop”.

Also, if you are not sure where the WordPress Loop begins, it is usually located inside of index.php in your theme folder and starts with:

//Beginning of the WordPress Loop located in index.php of theme
if ( have_posts() ) : while ( have_posts() ) : the_post();

The last step is to display my most recent video in the sidebar. To do this I decided my best course of action was to save the embed code of my videos into a custom field as well as within the content of the post. This would allow me to easily pull the embed code and I would still be able to add text along with my video within the content.

In the example below I used the custom field ‘embed’ in my posts. Just paste this code in your sidebar where you would like your video to be displayed.

Videos

You will notice I also included a link to my last video however you can remove this or replace it with a link to your video archive. This code should work with most video embed codes. Be sure to change the width and height so everything fits nicely into your sidebar.

And that’s it. Now all you need to do when adding a new video post is:

Hey Jon Bishop! Great post, especially since I have over 20 WP blogs (most with video) so this will help a lot!

Josh

Hey Jon, just came across your site and this post which looks like exactly what I need, but it doesn’t seem to be working for me. Not sure if the code up above that you’re saying should be added to the sidebar is complete, but there’s no opening or closing PHP tags, it ends on an tag that’s closing , but there’s no above this. I’m also not seeing anything in the code specifying to grab the embed custom field, but I’m not a PHP guy, just HTML and CSS. Any help?

http://websitetalkingheads.com video spokesperson

Interesting. This is actually helpful for something I was trying to figure out with the videos that we place on blogs. Our videos have an added issue of maintain the alpha channel using flash video but your code seems to be great. I wonder though if this method would also be more effective if you wanted to employ a video sitemap for indexing purposes?

http://www.jonbishop.com Jon Bishop

It seems like this could be accomplished with a custom page template and a custom query that displayed links to all posts within the video category. Glad you liked the post.

http://wordpresshostinghq.com Mark

Very nice thoughts information John. I like to do some test sometime in one of my site.

http://curtismchale.ca curtismchale

A better way of excluding a category is to use the ‘category_name’ combined with the category slug. If you move a site then the category number in the DB may change while the slug will stay the same. Should save you work in the long run.

http://kitkonsult.se Kiper IT-konsult

Great post! I am suprised there is no comments!

I am working on something similar where the video posts will be fetched to a playlist widget so that when you click on the playlist item you will get forwarded to the actual video post page.
And as an extra feature I hope to sync youtube comments with wp comments so that you get the full comment stream at both places…

Jon Bishop

I'm a Web Developer and Digital Generalist. I spend most of my time creating interactive experiences with anything that can be connected to the internet.

I currently work at @AMP_Agency as the Director of Creative Technology in Boston, MA.