Here's how to sort subalbums

[Edited to add: this applies to themes derived from "testing-dev", which have subalbum support]

In the absence of a pukka solution upstream of the page, this will sort subalbums by title. (You can easily work out how to sort by something else). In the file album.php, replace the entire div called "albums" with the following:

Your PHP version may not like the "&" in the "foreach" line, if this is the case, remove the &, it will still work, but will be making copies of the array elements instead of accessing them by reference. Slightly less efficient that's all.

(some long lines will have wrapped and may want repairing when you copy & paste this):

`



<?php function printSortedAlbumThumbImage($alt, $thumb, $class=NULL, $id=NULL) { <br />
echo "
(($class) ? " class="$class"" : "") .

(($id) ? " id="$id"" : "") . " />";

} ?>

<?php while (next_album()):<br />
$title = getAlbumTitle();

$albums[$title]["title"] = $title;

$albums[$title]["url"] = wpGetAlbumLinkURL();

$albums[$title]["desc"] = getAlbumDesc();

$albums[$title]["thumb"] = getAlbumThumb();

endwhile;

if ($albums) {

array_multisort($albums, SORT_ASC);

foreach ($albums as &$album) { ?>






<?php } ?>

<?php } ?>



`

Comments

  • trisweb Administrator
    You could also apply the sort directly to the `$_zp_current_albums` array after initializing it with `next_album()` (use a `$firstrun` boolean variable or something). Set `$_zp_current_album` to `new Album($_zp_gallery, $_zp_current_albums[0])` right after sorting to get the correct first element.

    This is a hack though; it'd be better to set the sort_order field in the database once and make the getSubalbums method obey that, which is not difficult. I will have this done in the next release.
  • Hi,

    I tried to use this code because if for me important to maintain an order in subalbums.

    Only worked if I modify
    `echo "";} ?>`

    with something easier like

    `echo "image";`

    But my question is

    How can I sort with some other field else that name?
    Someone have some code writen that works?

    Thank sin advance.
Sign In or Register to comment.