Flickr: Link Your Photos Back To Your Blog – Stuart Herbert
Feb 12, 2011
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 ? 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. require_once(?phpflickr-3.0/phpFlickr.php?); $flickrApiKey = ?<your Flickr API key>?; $f = new phpFlickr($flickrApiKey, $flickrSecret); // first step ? find the first published blog post $blogPosts = array(); $latestPost = $matches[1]; function updatePhotos($photoIndex, $flickrPhotos, Truncated by Planet PHP, read more at the original (another 22896 bytes)
$flickrSecret = ?<your Flickr API secret>?;
$flickrToken ?= ?<your Flickr auth token>?;
$f->setToken($flickrToken);
$f->enableCache(?fs?, ?/tmp?, 3600);
$url = ?http://blog.stuartherbert.com/photography/?;
$rawHtml = file_get_contents($url);
preg_match(?/<h2 id=”post-([0-9]+)”>/?, $rawHtml, $matches);
$flickrPhotos = array();
$nextPost = $url . ??p=? . $latestPost;


