Last active
August 29, 2015 14:02
-
-
Save ItsRab/6301944243dd4b9e3604 to your computer and use it in GitHub Desktop.
Pull in latest images from Flickr in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Load in Flickr XML feed | |
$xml = simplexml_load_file('https://api.flickr.com/services/feeds/photos_public.gne?id=108874017@N08'); | |
// Check the feed | |
if (strlen($xml) == 0) { | |
// If the XML feed is empty (feed down) just display a link to Flickr | |
echo '<p>I quite like taking pictures. Check out <a href="https://www.flickr.com/photos/108874017@N08/" title="ItsRab on Flickr">my Flickr</a> for all my latest photos from all over the place. It’s just a hobby mind you.</p>'; | |
} else { | |
// Feed returned something, let’s show it! | |
echo '<p>I quite like taking pictures. Here’s a few of the latest ones, but there’s even more on <a href="https://www.flickr.com/photos/108874017@N08/" title="ItsRab on Flickr">my Flickr</a> if you fancy a nosey!</p>'; | |
echo '<ul class="flickr-list">'; | |
$i = 1; | |
// Loop through the feed grabbing what we need | |
foreach ($xml->entry as $row) { | |
$img_title = $row->title; | |
$img_url = $row->link[0]['href']; | |
$img_src = $row->link[1]['href']; | |
$img_src_z = str_replace("_b","_z",$img_src); | |
// Display the images from Flickr linking through to photo | |
echo '<li class=\'flickr-list__item\'>'; | |
echo '<a href=\'' . $img_url . '\'>'; | |
echo '<img class=\'flickr-list__img--' . $i . '\' src="' . $img_src_z . '">'; | |
echo '</a>'; | |
echo '</li>'; | |
// Only want latest 5 images, then break loop | |
$i++; | |
if($i > '5') | |
break; | |
} | |
echo '</ul><!-- .flickr-list -->'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment