Tuesday, April 24, 2007

Flickr Widget

I thought I'd be nice and post a flickr widget I developed in response to the fact that other flickr widgets really sucked.

Here's the code for mine, to start things off:

<script type="text/javascript">
function jsonFlickrFeed(json)
{
document.writeln('<ul style="margin-bottom: 0;">');
var tpl = '<li><a href="{link}"><img width="150" src="{media}"/></a></li>';

for (var i = 0; i < 5 && i < json.items.length; i++)
{
document.writeln(
tpl.
replace('{link}', json.items[i].link).
replace('{media}', json.items[i].media.m)
);
}
document.writeln('</ul>');
}
</script>
<script src="http://api.flickr.com/services/feeds/photos_public.gne?id=33268241@N00&format=json" type="text/javascript"></script>
<a id="flickr_www" href="http://www.flickr.com"><strong style="color: rgb(57, 147, 255);">www.flick<span style="color: rgb(255, 28, 146);">r</span>.com</strong></a>
|
<a href="http://www.flickr.com/photos/sjohnr/"><strong style="color: rgb(57, 147, 255);">my flick<span style="color: rgb(255, 28, 146);">r</span></strong></a>


The important thing is really the url to the json feed for your flickr site. Mine is: http://api.flickr.com/services/feeds/photos_public.gne?id=33268241@N00&format=json

The id in the url is not too logical, so check your flickr site (look for the "Feed" link at the bottom for the id parameter of the url).

Also, the link to my flickr site is http://www.flickr.com/photos/sjohnr/ so change that link in the code to point to your site.

Otherwise, I'll let you figure out how to customize the other portions of the widget, since it's not that hard.

Demo


www.flickr.com|my flickr

3 comments:

MacGeek Pro said...

You should post a screenshot of the actual widget.

sjohnr said...

Not a bad idea. Screenshots are too much work though. I think I'll just put the widget in the post.

Biby Cletus said...

Nice post, its a really cool blog that you have here, keep up the good work, will be back.

Warm Regards

Biby Cletus - Blog