Flickr Fallback Thumbnails

In my last post I wrote something about a small plugin for Flickr thumbnails. Well, here it is. It’s a quick-and-dirty version that assumes everything is working (no conditionals) but well, on this site it does as you can see 😉

The class is something like this:

'names' ) );
if (count($tags)==0) return false;
$r = rand(0, count($tags)-1);
return $tags[$r];

function get_flickr_img ($tag, $count=1) {
$tag = urlencode($tag);
$thumb_url = “”;
$url = ‘’;
$url .= ‘’.$this->api_key.’&tags=’.$tag.’&per_page=’.$count;
$url .= ‘format=’.$format;

if (!wp_get_http( $url )) return;

$xml = simplexml_load_file($url);
if (!$xml) return false;
# http://farm{farm-id}{server-id}/{id}_{secret}.jpg

if (count ($xml->photos->photo)>0) {
foreach ($xml->photos->photo as $photo) {
$title = $photo[‘title’];
$farmid = $photo[‘farm’];
$serverid = $photo[‘server’];
$id = $photo[‘id’];
$secret = $photo[‘secret’];
$owner = $photo[‘owner’];
if ($count>1) $thumb_url[] = “http://farm{$farmid}{$serverid}/{$id}_{$secret}_m.jpg”;
else $thumb_url = “http://farm{$farmid}{$serverid}/{$id}_{$secret}_m.jpg”;

return $thumb_url;
} // get_flickr_img

function flickr_thumb_init( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( empty( $html ) ) {
return sprintf(
$this->get_flickr_img ( $this->random_tag($post_id) ),
get_option( ‘thumbnail_size_w’ ),
get_option( ‘thumbnail_size_h’ ) );
return $html;
} //flickr_thumb

$ft = new flickr_thumb();


Todo: integrate with open calais (see tagaroo; it would be great if they would have something like an API because I don’t want to hack their plugin – it could be so much more versatile than just autotagging. This is the kind of computing we need full control of because of bandwidth usage and other issues).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.