Hello

I am using "image gallery" and import images with "image_import".
Is there a way to change sorting order of displayed images (nodes), for example with sorting by node name? The current approach with time stamps is quite invonvenient when I want to add images later to an existing gallery.

Thanks for any help
Andre

Comments

beauregard’s picture

I changed in both the image_gallery and flash_gallery modul the ORDER BY Clause to ORDER BY n.title ASC.
This helped.

alanburke’s picture

Doing things the Drupal way..

Means avoiding hacking modules [because you'll have to repeat the hack when the module is updated], and changing things at the template level, if possible.

The solution I have does require some knowledge of the templating system.

I was in the same boat recently, trying to reorder a list of galleries.

Basically, you need to copy the function theme_image_gallery [all of it] to you template.php file,rename it phptemplate_image_gallery, and make some changes there.

The way this function works [as I understand it], is that it takes in an array of nodes, from elsewhere in the module, and spits out a gallery page with photos.

So what you want to do is reorder that array, before the function goes to spit out the images.

So Just before

if (count($images)) {

You call a function to reoder the array.
Now, PHP can reorder simple stuff with a varerty of "sort" functions, but your problem is that you want to reoder stuff based on a single attribute of each object in the array.
So you need usort

Try this


     function compareImages($x, $y)
{
 if ( $x->title == $y->title )
  return 0;
 else if ( $x->title < $y->title )
  return -1;
 else
  return 1;
}
   
   
  usort($images,'compareImages');
  

And see if it does the trick.

Later
Alan

beauregard’s picture

thanks! I will try this.

matt b’s picture

worked fine for me!