I am using justifiedimage gallery, swipebox anda PHP Flickr API Wrapper to return and display images in a gallery.
The trouble is, currently it displays the images obtained from a certain user account. Is there a way to modify the below code, so that it only displays images from "Southampton" as opposed to displaying images from a specified userID?
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="justifiedGallery/justifiedGallery.min.css" />
<script src="justifiedGallery/jquery.justifiedGallery.min.js"></script>
<script src="swipebox/src/js/jquery.swipebox.js"></script>
<link rel="stylesheet" href="swipebox/src/css/swipebox.css">
</head>
<div id="gallery">
<?php
include_once('./phpFlickr.php');
$key = "491566f49be9289"; // enter your API key here
$secret = "11eb02"; // enter your API secret here
$userid = "163300815@N05"; // Get flickr user id here. Currently points to Jasper Reddin
$f = new phpFlickr($key, $secret);
$response = $f->people_getPublicPhotos($userid, NULL, "url_m,url_h", 500)['photos']['photo'];
foreach ($response as $photo) {
$title = str_replace("'", "'", $photo['title']);
echo '<a href="' . $photo['url_h'] . '" class="swipebox" title="' . $title . '"><img alt="' . $title . '" src="' . $photo['url_m'] . '"></a>';
}
?>
</div>
<script>
$('#gallery').justifiedGallery( {
rowHeight: 200,
lastRow: 'nojustify',
rel: 'Portfolio',
margins: 2
});
$(".swipebox").swipebox({
loopAtEnd: true
});
</script>
<style>
body {
margin: 0;
}
#gallery {
background-color: black;
}
</style>
Since you didn't link to the PHP library you're using, I'm going to guess that it's this one by Dan Coulter , which I note was last updated 7 years ago. However, it allows you to call any method in the Flickr API with the ->call
method so you should be able to use any of the methods listed on Flickr's documentation to meet your goal.
In particular, there is a method simply called flickr.photos.search
which allows you to specify a lot of different options for what photos you want. Most relevantly:
user_id
to specify whose photos to return bbox
to specify a rectangular / quadrilateral geographical area lat
, lon
, radius
and radius_units
to specify a circular geographical area woe_id
or place_id
to specify identified places like towns The documentation says that you can't search for all photos in a certain location, and if you don't specify some other limit such as a tag or date, then only photos added in the last 12 hours will be returned.
To find values for woe_id
and place_id
, you can use the methods headed "Places", such as flickr.places.find
.
Both methods have wrappers in Dan Coulter's library, so your code might look something like this (completely untested):
$places = $f->places_find('Southampton')['places']['place'];
foreach ( $places as $place ) {
echo "<h2>{$place['_content']}</h2>";
$photos = $f->photos_search([
'place_id' => $place['place_id'],
// other search parameters here
'extras' => 'url_m,url_h',
'per_page' => 500
])['photos']['photo'];
foreach ( $photos as $photo ) {
$title = str_replace("'", "'", $photo['title']);
echo '<a href="' . $photo['url_h'] . '" class="swipebox" title="' . $title . '"><img alt="' . $title . '" src="' . $photo['url_m'] . '"></a>';
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.