News Archive
PhpRiot Newsletter
Your Email Address:

More information

Flickr: Link Your Photos Back To Your Blog

Note: This article was originally published at Planet PHP on 12 February 2011.
Planet PHP

I post photos to Flickr from time to time, and then write blog articles about the photos. The blog articles get written days, weeks, sometimes months in advance of when they're scheduled to appear on my blog a which makes it a tad difficult to add a link from a photo to all of the blog articles that mention it.

So a couple of weekends ago I knocked up a very crude script that uses the Flickr API (via phpFlickr) to work through all of the published blog posts and make sure each of my Flickr photos has links back to each blog post that mention it. I'm posting it here in the public domain. Hopefully someone will find it a useful starting point to do something similar for their own blog.


$flickrApiKey = a';
$flickrSecret = a';
$flickrToken A= a';

$f = new phpFlickr($flickrApiKey, $flickrSecret);
$f-enableCache(afs', a/tmp', 3600);

// first step - find the first published blog post
$url = a';
$rawHtml = file_get_contents($url);

/', $rawHtml, $matches);

$blogPosts = array();
$flickrPhotos = array();

$latestPost = $matches[1];
$nextPost = $url . a?p=' . $latestPost;

function updatePhotos($photoIndex, $flickrPhotos,

Truncated by Planet PHP, read more at the original (another 22896 bytes)