Hello,

can anybody tell me, how to change the sort order for images in my image gallery. At the moment the images are not sorted by names but by import date. The image which was imported last is in front and vice versa. I thought, views would be an usefull module, but it is not compatibe with version 6 of drupal.

I already searched with google, without success.

Thanks for help,

Greetings from Bielefeld in Germany

Comments

michaek’s picture

i'm not sure what's possible for sorting image galleries under 6.x, as i haven't looked 6 yet, but here's the approach that i have used in 5.7. though it's not a good idea to use the theme system for logic like sorting, that's where i put my sort code, because it was simplest to implement, and because on the sites i've used this on, i know one theme will be used for all users at all times. still, it's not best practice.

i placed the following into the theme's template.php file. in this example the theme is named "yourtheme" - you would replace that with the name of the theme you're using.

function yourtheme_image_gallery($galleries, $images) {
  // we'll sort the images using a comparison function
  function imageCompare($a, $b) {
    // compare stickiness
    if ($a->sticky != $b->sticky)
      return ($a->sticky < $b->sticky) ? 1 : -1;
    // compare title
    if ($a->title != $b->title)
      return ($a->title > $b->title) ? 1 : -1;
    // if we get to the end, the images are the same
    return 0;
  }
  usort($images, 'imageCompare');
  return theme_image_gallery($galleries, $images);
}

to get the sort ordering you want, customize the comparisons in imageCompare(). this example should sort images alphabetically by name, while keeping sticky nodes at the top.

falu’s picture

Thank You!

It works fine!

(5.x-1.9)

semperos’s picture

Assuming you have the basic Image module installed, as well as the 'Image Gallery' module that comes packaged with it, via the navigation menu, go to

Administer >> Site configuration >> Images

and click on the "Image gallery" tab. Under "Image Display Sort Order" choose an option that suits your needs.

Squizzy Taylor’s picture

Ok, I need some real basic help with this one. I have 5.7 and don't see the "Image Gallery Tab". My site developer has bugged out and I am very very slowly learning my way around.....I'm a stonemason not a website developer!. I'd just like to get my images in order.

WeRockYourWeb.com’s picture

Neither of these approaches worked for me unfortunately. The latest image 1.x module doesn't have the sort capability, and the 2.x module has so many changes (integration with views) that it completely loses my galleries.

I know this is a hack, but for lack of time and because I don't plan on upgrading the image gallery module, here's how I changed the sort order - in image_gallery.module, simply edit lines 149 and 157, and change ... ORDER BY ... n.created DESC -> n.created ASC. You could also replace n.created with n.title or however you want to sort.