Topic: sort images
Hi,
how can I sort images in a Google Fotos album using wp-juicebox by name?
Kind regards,
Edwin
You are not logged in. Please login or register.
Juicebox Support Forum → Juicebox-Pro Support → sort images
Hi,
how can I sort images in a Google Fotos album using wp-juicebox by name?
Kind regards,
Edwin
As noted in the Picasa Web Albums Data API developer's guide:
Note: The entries in a feed are ordered based upon the display order on the web site.
There does not seem to be a method in the API to request images in a specific sort order.
You'd need to fetch the images first and then sort the array (by image filename) manually afterwards.
Try the following.
Open the plugin's 'wp-juicebox.php' file in a plain text editor, scroll down to line 1351 and replace:
function get_attachments_picasa($picasa_user_id, $picasa_album_name) {
$attachments = array();
$name = $this->remove_whitespace($picasa_album_name);
$term = preg_match('/^[0-9]{19}$/', $name) ? 'albumid' : 'album';
$picasa_feed = 'http://picasaweb.google.com/data/feed/api/user/' . $this->remove_whitespace($picasa_user_id) . '/' . $term . '/' . $name . '?kind=photo&imgmax=1600';
$entries = @simplexml_load_file($picasa_feed);
if ($entries) {
foreach ($entries->entry as $entry) {
$attachments[] = $entry;
}
}
return $attachments;
}
... with:
function get_attachments_picasa($picasa_user_id, $picasa_album_name) {
$attachments = array();
$name = $this->remove_whitespace($picasa_album_name);
$term = preg_match('/^[0-9]{19}$/', $name) ? 'albumid' : 'album';
$picasa_feed = 'http://picasaweb.google.com/data/feed/api/user/' . $this->remove_whitespace($picasa_user_id) . '/' . $term . '/' . $name . '?kind=photo&imgmax=1600';
$entries = @simplexml_load_file($picasa_feed);
if ($entries) {
foreach ($entries->entry as $entry) {
$attachments[] = $entry;
}
}
usort($attachments, array(&$this, 'sort_picasa_images'));
return $attachments;
}
function sort_picasa_images($a, $b) {
$a_filename = basename($a->content->attributes()->src);
$b_filename = basename($b->content->attributes()->src);
return strnatcasecmp($a_filename, $b_filename);
}
Hopefully this will work for you.
Please note that the line number above refers to the current version of WP-Juicebox (v1.5.0).
I will nog try this solution because it would affect all albums on my site. I will have to make sure each album is in the order I want. Unfortunately google fotos does not offer the same sort options as picasa did (picasa allowed sorting by filename for example). I actually wonder who is happy with the forced switch from Picasa to Google Fotos, I have only read complaints on the internet.
Thanks anyway steve.
If you wanted to sort the images only in specific galleries, then you'd really need to create a new variable for each gallery, check the variable when the images are fetched from Google and sort the images if necessary depending on the value of the variable. This would be much more complicated to implement (you'd need to make several changes across three different plugin files) and, if you have only one or two galleries that you'd like to sort, then it might be easier to just rearrange the images in the Google Photos interface (if that's possible).
Juicebox Support Forum → Juicebox-Pro Support → sort images
Powered by PunBB, supported by Informer Technologies, Inc.