Save $50 on Dreamhost Hosting - Any Plan

As a preferred visitor, you can get $50 off of any Dreamhost hosting plan by using coupon code CWD50 when you check out, for a limited time. Dreamhost is a reliable hosting provider with solid customer service and a proven track record.

Get Your Own Toll Free 800 Number

It's easy to setup your own toll free number for as little as $2/ month. Try Kall8 today and get your 800 number. Features include call forwarding, voice mail and fax, caller ID, email notifications, VoIP, and more.



Jun 10 2009

Drupal - Change Sort Order for Image Gallery


Filed under: Content Management Systems » Drupal,
Tools:


Sorting Drupal's Image Gallery

Drupal has so many different image modules at different stages of development, and different means of handling images, that chances are this technique won't apply to you. But for those that are using the 1.x release of the Image module (which doesn't contain the image gallery sorting feature), here's how to get your images sorted by either title, creation date, or any other attribute.

Sorting Images in Image Module 2.x

If you're using Image module 2.x, you don't need to apply the hack below. Simply browse to Administer -> Site Configuration -> Images, select the Image Gallery tab, and select an option under Image Display Sort Order. If you don't see the Image Gallery tab, or the Image module tells you you need to configure Views, you may want to consider the approach below. Caution, however, as if you downgrade your image module you may lose your images. It's always best to create database backups before and after changes to modules.

Editing the Image Gallery Module

In most cases you don't want to edit core Drupal modules directly. Why? Because it doesn't promote a clean "black box" coding environment. In other words, if there's not an organized and unified way of upgrading and changing core code, changes will get lost. But in this case, I feel it's justified since so many iterations of the image module apply, and those using this particular approach aren't likely to upgrade. If you do, you'll need to start over with your images in any case.

Sorting Images in Drupal Image Gallery by Title or Date

Open the image_gallery module (image_gallery.module) in the "contrib" directory of your image gallery directory, within the image module. Browse down to lines 149 and 157. You'll see the database calls for generating the image galleries:

149$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';

157:     $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"),...

Simply change the n.created DESC to a variable of your choosing, followed by your preferred sort order. For example, if you want to sort by date created, ascending, you would substitute: n.created ASC. If, on the other hand, you want to sort your image gallery images by descending title (reverse alphabetical), you would use: n.title DESC.

Average: 5 (2 votes)
Tools:



  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br> <br />
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.