Hello all,
I am a newbie and am tired of searching the web for a answer for this problem and decided to bug you all with this simple question (witch i hope no one asked). How do you change the code in to the images in the gallery be sorted by name?

Sorry for the bad english and thanks for reading this

Comments

drewish’s picture

you could probably just add an ORDER BY n.title to the query... i don't have the code in front of me right now but it shouldn't be too terribly hard to figure out.

Bananoide’s picture

Cool. It did the job. i was trying n.name (dumb dumb dumb). Thks a lot!

drewish’s picture

Status: Active » Closed (fixed)
benone’s picture

And where exactly did you put it ? Which file and line ?

dougpetch’s picture

To echo benone - could someone post the correct code along with where it should be positioned in the image_gallery.module file?

halftone’s picture

I don't have Image 5.1.4 in front of me but look for the SQL queries in the function image_gallery_page in the Image_gallery module. In later versions this is around line 141

Change

    $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';

to

    $sql = 'SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('. implode(',', $descendant_tids) .') AND n.status = 1 ORDER BY n.sticky DESC, n.title ASC';

and (a few lines further down) change

$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.created DESC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);

to

$result = pager_query(db_rewrite_sql("SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d ORDER BY n.sticky DESC, n.title ASC"), variable_get('image_images_per_page', 6), 0, db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid WHERE n.status=1 AND n.type='image' AND t.tid=%d"), $tid);

I've now stopped using this method of ordering. More flexible and useful - to me anyhow - is using the Nodeorder module to enable drag and drop ordering of images within the gallery. See http://drupal.org/node/317902