I had an idea of displaying YouTube Videos on my website using a playlist.
It’s very very easy and fast to create youtube playlists so I thought I’d share this:
[!YouTube? &playlist=`############`!]
http://www.youtube.com/view_play_list?p=A81CDB7123387C26
<?php
if (!isset($playlist)) {
$playlist = 'A81CDB7123387C26';
}
$smooth_url = 'http://gdata.youtube.com/feeds/api/playlists/'.$playlist;
$ch = curl_init($smooth_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
// SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response tags, so take them out
$xmlString = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $data);
// Use SimpleXML to parse response into object
$xml = new SimpleXMLElement($xmlString);
$smug_items = $xml->entry;
$count = count($xml->entry);
$output .= '<ul style="list-style:none;"';
while ($i < $count): $i++;
{
if (isset($smug_items[$i-1]->mediagroup->mediathumbnail)) {
$LINK = $smug_items[$i-1]->link[0]->attributes()->href;
$IMAGE = $smug_items[$i-1]->mediagroup->mediathumbnail[3]->attributes()->url;
$output .= '<li style="float: left; margin: 10px 10px 0 10px">';
$output .= '<a class="tip4" href="'.$LINK.'">'.'<img width="170" src="'.$IMAGE.'"></a>';
$output .= '</li>';
}
}
endwhile;
$output .= '</ul>';
return $output;
?>