Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created October 21, 2014 16:31
Show Gist options
  • Save mloberg/2a02b976c96c7bf9c9d4 to your computer and use it in GitHub Desktop.
Save mloberg/2a02b976c96c7bf9c9d4 to your computer and use it in GitHub Desktop.
Display Flickr photos
<?php
$id = '30065870@N08'; // Find your Flickr ID at http://idgettr.com
$url = 'http://api.flickr.com/services/feeds/photos_public.gne?id='.$id.'&format=json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
// Remove jsonp callback (jsonFlickrFeed) and escaped characters (except ")
$json = preg_replace('/\\\([^"])/', '$1', substr($response, 15, -1));
$flickr = json_decode($json);
$display = 5;
?>
<html>
<head>
<title>Flickr Feed</title>
</head>
<body>
<h1><a href="<?= $flickr->link; ?>"><?= $flickr->title; ?></a></h1>
<p><?= $flickr->description; ?></p>
<?php
for ($i = 0; $i < $display; $i++):
$photo = $flickr->items[$i];
?>
<div class="photo">
<a href="<?= $photo->link; ?>">
<img src="<?= $photo->media->m; ?>" alt="<?= $photo->title; ?>">
</a>
<p><?= $photo->title; ?></p>
</div>
<?php endfor; ?>
<p><a href="<?= $flickr->link; ?>">View all photos</a></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment