My YouTube Favourites
by Douglas McGregor on Jul.27, 2009, under Geeky Stuff
Morning all,
I've been writing this plugin for WordPress that gets a users YouTube favourite videos. Or rather I was, but I've decided for the time being it's simply easier to put it in as actual code.
You have to be PHP literate in order to do this. It seems logical, since WordPress is written in PHP. First of all, create a new folder in the root folder of your WordPress installation, called "wp-library". This library will contain the Zend Framework, as well as any other libraries you may wish to install in the future. Download the Zend Framework here.
The downloaded folder should be called "ZendFramework-1.8.4PL1". Fire up your FTP software (I use WS_FTP) and go to the downloaded folder, go to "library" and select "Zend". Hit the upload button. This should take a wee while to upload, so feel free to do other things while you're waiting.
Once that is uploaded, in your WordPress theme, open "sidebar.php". Look for the following code:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar_full') ) : ?>
<li>
<div class="sidebarbox">
<h2>Recent Posts</h2>
<ul>
<?php wp_get_archives('type=postbypost&limit=10'); ?>
</ul>
</div>
</li><li>
<div class="sidebarbox">
<h2>Browse by tags</h2>
<?php wp_tag_cloud('smallest=8&largest=17&number=30'); ?>
</div>
</li><?php endif; ?>
Directly after this, add the following code:
<li>
<div class="sidebarbox">
<h2>My YouTube Favourites</h2><?php
set_include_path('.' . PATH_SEPARATOR . 'wp-library' . PATH_SEPARATOR . get_include_path());
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt->getUserFavorites('Shuggy23');
$a = -5;
echo "<table cellpadding='5' cellspacing='5'>";
foreach ($videoFeed as $yt) {
$videoId = $yt->getVideoId();
$YouTube_Link = "<a href='http://www.youtube.com/watch?v=" . $videoId . "' target='_blank'><img src='" . $yt->mediaGroup->thumbnail[0]->url . "' width='50' height='35' title='" . $yt->getVideoTitle() . "' /></a>";
if ($a == '0') {echo "<tr>";}
if ($a == '5') {echo "<tr>";}
if ($a == '10') {echo "<tr>";}
if ($a == '15') {echo "<tr>";}
echo "<td>";
echo $YouTube_Link;
echo "</td>";
$a = $a + 1;
} // closes for eachecho "</table>";
?></li>
</div>
This adds a new section to the sidebar, like a widget would do. The idea is that it displays an image gallery of your recent YouTube favourites, and when you click on an image it links directly to the video on YouTube. I think it's pretty funky. There have been similar ideas in the past, but they provide a video player for WordPress, but in my opinion, this seems like a much neater approach.
There are still vast improvements I could make to this, but needless to say, the basics are working. You can see a working demo here on this site. I'm not a PHP programmer, I come from an ASP background, I find it easier to understand. I hope someone finds this useful.
As Aleksandr Orlov – founder of CompareTheMeerkat.com would say, "Simples!".
