Last active
August 29, 2015 13:57
-
-
Save fredbradley/9812791 to your computer and use it in GitHub Desktop.
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
<? | |
/** | |
* Some custom code written by Fred that will pull in all the photos in given photosets | |
*/ | |
// First we Add some custom styles! Not ideal, and not compliant but quick and easy! ?> | |
<style> | |
ul.flickr-photos, | |
ul.flickr-photos li { | |
list-style:none; | |
} | |
ul.flickr-photos li { | |
float:left; | |
margin:5px; | |
} | |
.skip-links a {} | |
</style> | |
<?php | |
/* Here are some variables that you can edit! */ | |
define('FLICKR_API_KEY','556fc298bc1e85496131e4039c46c87f'); | |
define('FLICKR_USERNAME', '120835093@N02'); | |
// Next we list the photoset IDs for each photoset we want to diplay the photos of. | |
// This is used for the menu, and for grabbing each photo from each photoset. | |
$photosets = array( | |
'Networking Photos' => '72157642679861584', | |
'Exhibition Photos' => '72157642679817704', | |
'Workshop' => '72157642679737604', | |
'Conference' => '72157642679687954', | |
'Speakers' => '72157642679592054', | |
'Retail Week Live' => '72157642597797104' | |
); | |
echo "<div class=\"skip-links\">"; | |
echo "Skip to section"; | |
foreach ($photosets as $key => $link) { | |
echo " | <a href=\"#".$link."\">".$key."</a>"; | |
} | |
echo "</div>"; | |
// Now we go through this next section of code repeating for each of those IDs that you have put in the line above! | |
foreach ($photosets as $photoset) { | |
// Go and grab the XML API from Flickr, adding the photoset ID at the end (called from the list above) | |
$uri = "https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=".FLICKR_API_KEY.'&photoset_id=".$photoset; | |
// Now we load the XML that the API has given us | |
$xml = simplexml_load_file($uri); | |
// Write the title in a <h2> tag. This is the title that you have given the set in Flickr. | |
// (If you want to change this title, then change it in Flickr - you lazy fool! | |
echo "\n<a name=\"".$photoset."\"></a>"; | |
echo "<h2>".$xml->photoset['title']."</h2>"; | |
// We start out list of photos | |
echo "<ul class=\"flickr-photos\">"; | |
// We go through each photo in the photoset, creating a list item, link and image. | |
foreach ($xml->photoset->photo as $photo) { | |
echo "<li>"; | |
$link = "https://www.flickr.com/photos/'.FLICKR_USERNAME.'/".$photo['id']."/in/set-".$photoset; | |
echo "<a target=\"_blank\" href=\"".$link."\" onclick=\"javascript:void window.open('".$link."','".$photo['id']."','width=800,height=400,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0');return false;\">"; | |
echo "<img src=\"//farm".$photo['farm'].".staticflickr.com/".$photo['server']."/".$photo['id']."_".$photo['secret']."_s.jpg\" />"; | |
echo "</a>"; | |
echo "</li>"; | |
} // Close the foreach | |
// Close the list item | |
echo "</ul>"; | |
// Add a clearing div so we don't all go mad! | |
echo "<div class=\"clear clearfix\"> </div>\n\n"; | |
echo "<p><a href=\"#skip-link\">Back to top</a></p>"; | |
} // Close the foreach | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment