1 (edited by charmedlife 2017-04-25 20:16:36)

Topic: Image order pro WP gallery not reflect order change in google album

This is the album as it is ordered in google photos: https://goo.gl/photos/sRVweuVmd8btmnAM9

As I write this, this order is not reflected in the JB gallery on this page: https://gateslosangeles.com/glass-and-s … ences.html

I have cleared the cache and tried FF, Chrome and Safari. I have gone into the gallery dashboard in the WP JB for my site and re-saved the settings and still no change.

I deleted some images, and these did not again show in the wp jb gallery (expected behavior and that is good.)

I want the order in JB to be the order that is in the google album.

Thanks

Re: Image order pro WP gallery not reflect order change in google album

Unfortunately, there is no method in the Picasa Web Albums Data API to request images in a specific sort order.
According to 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.

It certainly seems strange that the API (which WP-Juicebox uses to fetch the images) does not return images in the same order as seen on your Google web page but WP-Juicebox just displays the images in the order in which they are returned.

If you want to re-order the images, you'd need to fetch the images first (in the order in which they are returned by Google) and then sort the array of images manually afterwards by whatever criterion you'd like to use. For example, you could order the images by id, published date, updated date, title, summary or filename (all of which are returned as part of the image data and are available to work with).

First of all, you'd need to add functions to WP-Juicebox so that the images could be ordered using each of the available criteria.
You'd then need to instruct WP-Juicebox to use one of these methods after fetching the images.

Open the WP-Juicebox plugin's 'wp-juicebox.php' file in a plain text editor, scroll down to line 1344 and replace:

/**
 * Get attachments Picasa
 *
 * @param string Picasa user id
 * @param string Picasa album name
 * @return array attachments
 */
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:

/**
 * Get attachments Picasa
 *
 * @param string Picasa user id
 * @param string Picasa album name
 * @return array attachments
 */
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_xxxxxxxxx'));
    return $attachments;
}

/**
 * Sort Picasa id
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_id($a, $b) {
    $a_id = intval(basename($a->id));
    $b_id = intval(basename($b->id));
    if ($a_id === $b_id) {
        return 0;
    }
    return $a_id < $b_id ? -1 : 1;
}

/**
 * Sort Picasa published
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_published($a, $b) {
    $a_published = intval(strtotime($a->published));
    $b_published = intval(strtotime($b->published));
    if ($a_published === $b_published) {
        return 0;
    }
    return $a_published < $b_published ? -1 : 1;
}

/**
 * Sort Picasa updated
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_updated($a, $b) {
    $a_updated = intval(strtotime($a->updated));
    $b_updated = intval(strtotime($b->updated));
    if ($a_updated === $b_updated) {
        return 0;
    }
    return $a_updated < $b_updated ? -1 : 1;
}

/**
 * Sort Picasa filename
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_filename($a, $b) {
    $a_filename = basename($a->content->attributes()->src);
    $b_filename = basename($b->content->attributes()->src);
    return strnatcasecmp($a_filename, $b_filename);
}

/**
 * Sort Picasa title
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_title($a, $b) {
    $a_title = strval($a->title);
    $b_title = strval($b->title);
    return strnatcasecmp($a_title, $b_title);
}

/**
 * Sort Picasa summary
 *
 * @param string image
 * @param string image
 * @return integer image
 */
function sort_picasa_summary($a, $b) {
    $a_summary = strval($a->summary);
    $b_summary = strval($b->summary);
    return strnatcasecmp($a_summary, $b_summary);
}

Then, all you'd need to do is replace sort_picasa_xxxxxxxxx in the code above with the name of the function you'd like to use to order your images, e.g. sort_picasa_filename.

I hope this helps.

Please note that the line number above refers to the current version of WP-Juicebox (v1.5.0.1).

Re: Image order pro WP gallery not reflect order change in google album

Thank you very much. You said that these are my options: "you could order the images by id, published date, updated date, title, summary or filename...", I am guessing that these are my only options, yes?

Would "updated date" be the time that I last edited and saved the album?

You see, I don't want to have the images in any of the orders you have mentioned here, unless "updated date" refers to the time the album was last edited and saved. 

You see, what I have done is arranged (in the google photos album) the various photos in a completely arbitrary order, which is just by my judgement of "these would look good there".

On that basis, I am imagining that I could re-name each image by title, such as a-1.jpg, a-2.jpg, a-3.jpg, etc. and then chose the "by title" configuration as you gave me. Are you aware of a better work-around?

Dan

Re: Image order pro WP gallery not reflect order change in google album

I am guessing that these are my only options, yes?

Pretty much... When the images are returned via the API, the array contains certain data along with the image URL.
I listed the data that could be useful in sorting the images. There are certain other attributes attached to each image but they would be much less useful in sorting such as the image type (e.g. "image/jpeg").
The display order for each image is not stored as array values.

The images should be returned (and displayed by WP-Juicebox) in the display order (according to Google's own documentation - see the quote in my post above) and, unfortunately, if the images are returned in a different order, then there is little that WP-Juicebox can do to re-order the images other than manually sort the array using whatever attributes are available.

I realise that you already use Google Photos but if you want to have more control over the order of images in your WP-Juicebox galleries, then you might like to try using a different image source (such as the WordPress Media Library or Flickr). It would be much easier to re-order images using either of these sources.

Would "updated date" be the time that I last edited and saved the album?

I expect the 'updated' date would be the time that you last edited a particular image. (I notice that in my own test album, each image has a different 'updated' date so 'updated' seems to refer to individual images rather than the gallery as a whole.)

On that basis, I am imagining that I could re-name each image by title, such as a-1.jpg, a-2.jpg, a-3.jpg, etc. and then chose the "by title" configuration as you gave me. Are you aware of a better work-around?

You could certainly do that (or you could add alphabetical or numerical descriptions to all your images, sort by 'summary' and then tweak the WP-Juicebox code to prevent these image captions from being displayed in the gallery) but it would probably be quicker and easier to just re-upload the images to either the WordPress Media Library or Flickr and use the built-in sorting methods that these alternative image sources offer.