I just added a Flickr badge to Generator.x using the excellent phpFlickr library. The code to retrieve the images from the Generator.x Flickr group is less than 20 lines. I turned it into a function and put inside a basic WP plugin shell, giving me a new API call for inserting into the sidebar.php template.
Code - gxflickr.php
/*
Plugin Name: Generator.x Flickr utilities
Plugin URI: http://www.generatorx.no/
Description: Support utilities for Generator.x web
Version: 1.0
Author: Marius Watz
Author URI: http://www.generatorx.no/
*/
require_once("phpFlickr/phpFlickr.php");
function gxFlickrSidebar() {
$f = new phpFlickr("API_KEY");
$f->enableCache(
"dbname",
"mysql://username:password@host/dbname"
);
echo("<div class=\"gxflickrSidebar\">");
echo("<div class=\"gxFlickrTitle\"><a href=
\"http://flickr.com/groups/generatorx/\">".
"» GX on Flickr:</a> Recent images</div>");
// get photos using the Generator.x group's ID
$photos = $f->groups_pools_getPhotos('59096658@N00', NULL, NULL, NULL, 12);
foreach ((array)$photos['photo'] as $photo) {
echo “<a href=http://www.flickr.com/photos/” . $photo['owner'] .
“/” . $photo['id'] .”/in/pool-generatorx>”;
echo “<img border=’0′ alt=’$photo[ownername]: $photo[title]‘ src=” .
$f->buildPhotoURL($photo, “Square”) . “>”;
echo “</a>”;
}
echo(”</div>”);
}
Once that’s done, all you need to do is insert the function call in your Wordpress template:
[..html..]
if (is_home() || is_page()) {
gxFlickrSidebar();
}
[..html..]
Comment on this entry




