Skip to content

Instantly share code, notes, and snippets.

@hathaway
Created February 23, 2011 02:33
Show Gist options
  • Save hathaway/839877 to your computer and use it in GitHub Desktop.
Save hathaway/839877 to your computer and use it in GitHub Desktop.
Load photos from flickr with jQuery
var next_page = 1;
function load_photos(page, per_page)
{
// Load flickr images
var flickr_url = "http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&jsoncallback=?";
$.getJSON(flickr_url,
{
api_key: "GET_YOUR_OWN_API_KEY_FROM_FLICKR",
user_id: "23295851@N04",
format: "json",
extras: "tags",
per_page: per_page,
page: page
},
function(data)
{
$("#load_more_photos .spinner").show();
$.each(data.photos.photo, function(i,item)
{
if(item.tags.toLowerCase().indexOf("lincoln") != -1)
{
var image_thumbnail_url = "http://farm" + item.farm + ".static.flickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_s.jpg";
var image_url = "http://farm" + item.farm + ".static.flickr.com/" + item.server + "/" + item.id + "_" + item.secret + ".jpg";
$("#photos").append(
$("<li>").append(
$("<a>").append(
$("<img/>").attr("src", image_thumbnail_url).attr("border", "0")
).attr("href", image_url).attr("class", "photo").attr("rel", "main_gallery").attr("alt", item.title).attr("title", item.title)
)
);
}
}
);
// Initialize Fancybox
$("a.photo").fancybox({
"titlePosition": "over"
});
$("#load_more_photos .spinner").hide();
$("#load_more_photos a").show();
}
);
next_page++;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment