Order

This page demonstrates the new (from Thumblist² on) parameter to sort the files displayed in the thumblist.

Here are the files:

img1.png 3,5052009-05-19 19:34
img2.gif 3,5902009-02-13 12:43
img3.png 2,4902009-02-13 12:43
img4.jpg 3,9082009-05-19 19:36
img11.jpg 3,7172009-05-19 19:34
img20.png 3,1772009-02-13 12:43
img42.png 13,6742009-05-19 19:36
img100.png 6,9312009-05-19 19:34

In the old version, the list was always sorted by the filename, or shuffled. It is now possible to sort also by extension, file last modified time, file size, width, height and ratio, with the parameter order=. If you use a "minus", like order=-time, the filelist will be reversed.

It is also possible to write your own sorting functions, see below.

Note that when a thumblist displays only a part of all files in the upload directory (with count=X..Y), ordering the files by time, size, width, height and ratio may be noticeably slower, as the script will need to open every file in the upload directory in order to read this additional information. If you are not using count=, then the speed is about the same.

Examples

No order specified (same as order=name, because it was the default behavior in previous versions):

(:thumblist Order. px=30:)
img1.png: 90x120, 3k (2009-05-19 19:34) img2.gif: 120x120, 4k (2009-02-13 12:43) img3.png: 120x72, 2k (2009-02-13 12:43) img4.jpg: 88x120, 4k (2009-05-19 19:36) img11.jpg: 101x120, 4k (2009-05-19 19:34) img20.png: 120x74, 3k (2009-02-13 12:43) img42.png: 120x73, 13k (2009-05-19 19:36) img100.png: 120x120, 7k (2009-05-19 19:34)

You can change the default order by adding in your config.php for example:

 $ThumbList['FileListOrder'] = '-time';

Note: the files are uploaded to a group Order, that's why the lines start with "thumblist Order.".

order=none (should be what returned the directory listing, FASTEST):

(:thumblist Order. px=30 order=none:)
img3.png: 120x72, 2k (2009-02-13 12:43) img20.png: 120x74, 3k (2009-02-13 12:43) img100.png: 120x120, 7k (2009-05-19 19:34) img2.gif: 120x120, 4k (2009-02-13 12:43) img1.png: 90x120, 3k (2009-05-19 19:34) img11.jpg: 101x120, 4k (2009-05-19 19:34) img4.jpg: 88x120, 4k (2009-05-19 19:36) img42.png: 120x73, 13k (2009-05-19 19:36)

order=-name (reversed sort by filename):

(:thumblist Order. px=30 order=-name:)
img100.png: 120x120, 7k (2009-05-19 19:34) img42.png: 120x73, 13k (2009-05-19 19:36) img20.png: 120x74, 3k (2009-02-13 12:43) img11.jpg: 101x120, 4k (2009-05-19 19:34) img4.jpg: 88x120, 4k (2009-05-19 19:36) img3.png: 120x72, 2k (2009-02-13 12:43) img2.gif: 120x120, 4k (2009-02-13 12:43) img1.png: 90x120, 3k (2009-05-19 19:34)

order=ext (.gif, then .jpg, then .png):

(:thumblist Order. px=30 order=ext:)
img2.gif: 120x120, 4k (2009-02-13 12:43) img11.jpg: 101x120, 4k (2009-05-19 19:34) img4.jpg: 88x120, 4k (2009-05-19 19:36) img42.png: 120x73, 13k (2009-05-19 19:36) img1.png: 90x120, 3k (2009-05-19 19:34) img100.png: 120x120, 7k (2009-05-19 19:34) img3.png: 120x72, 2k (2009-02-13 12:43) img20.png: 120x74, 3k (2009-02-13 12:43)

order=ratio orders by width/height:

(:thumblist Order. px=30 order=-ratio titlefmt="?w/?h = ?r":)
120/72 = 1.67 120/73 = 1.64 120/74 = 1.62 120/120 = 1 120/120 = 1 101/120 = 0.84 90/120 = 0.75 88/120 = 0.73

order=random (see Shuffle for details):

(:thumblist Order. px=30 order=random:)
img3.png: 120x72, 2k (2009-02-13 12:43) img4.jpg: 88x120, 4k (2009-05-19 19:36) img11.jpg: 101x120, 4k (2009-05-19 19:34) img2.gif: 120x120, 4k (2009-02-13 12:43) img1.png: 90x120, 3k (2009-05-19 19:34) img42.png: 120x73, 13k (2009-05-19 19:36) img100.png: 120x120, 7k (2009-05-19 19:34) img20.png: 120x74, 3k (2009-02-13 12:43)

Thumbgallery

With a thumbgallery the images are displayed in the order they are defined.

(:thumbgallery Order. px=30:)
img2.gif
img11.jpg
img3.png
img1.png
img42.png
(:thumbgalleryend:)
img2.gif: 120x120, 4k (2009-02-13 12:43) img11.jpg: 101x120, 4k (2009-05-19 19:34) img3.png: 120x72, 2k (2009-02-13 12:43) img1.png: 90x120, 3k (2009-05-19 19:34) img42.png: 120x73, 13k (2009-05-19 19:36)

Write your own sort function

This is an advanced topic. If you don't understand everything here, it is advisable not to write the function yourself (we can write it for you).

Thumblist² comes with a really flexible code and numerous hooks to enable your own features. There are two ways to do it:

(Advanced.) Write a user function similar to ThumbOrderFileList(), for example "uThumbOrderFileList()" and set in config.php

 $ThumbList['fOrderFileList'] = 'uThumbOrderFileList';

(Easier.) Write a short callback function and place it in the $ThumbList['OrderFunctions'] array (see how it is done).

For example, if you want to sort the files by area (square pixels), here is what you will do:

# force a getimagesize() on the file, for the order=area parameter
$ThumbList['stat_dirlist']['area'] = 'getimagesize';

# define the order function
$ThumbList['OrderFunctions']['area'] = 
  '$c=$a["getimagesize"];$d=$b["getimagesize"]; return $c[0]*$c[1]-$d[0]*$d[1];';

And the result is:

(:thumblist Order. px=30 order=area titlefmt="?wx?h=?a px²":)
90x120=10800 px² 120x120=14400 px² 120x72=8640 px² 88x120=10560 px² 101x120=12120 px² 120x74=8880 px² 120x73=8760 px² 120x120=14400 px²
(:thumblist Order. px=30 order=-area titlefmt="?wx?h=?a px²":)
120x120=14400 px² 120x73=8760 px² 120x74=8880 px² 101x120=12120 px² 88x120=10560 px² 120x72=8640 px² 120x120=14400 px² 90x120=10800 px²

Multiple ordering, unrecognized order functions

Ordering by two or more order functions, or by a function that is not recognized, is not supported and is ignored (order=name is used instead, no error message is given).

(:thumblist Order. px=30 order=-ext,name:)
img1.png: 90x120, 3k (2009-05-19 19:34) img2.gif: 120x120, 4k (2009-02-13 12:43) img3.png: 120x72, 2k (2009-02-13 12:43) img4.jpg: 88x120, 4k (2009-05-19 19:36) img11.jpg: 101x120, 4k (2009-05-19 19:34) img20.png: 120x74, 3k (2009-02-13 12:43) img42.png: 120x73, 13k (2009-05-19 19:36) img100.png: 120x120, 7k (2009-05-19 19:34)
(:thumblist Order. px=30 order=color:)
img1.png: 90x120, 3k (2009-05-19 19:34) img2.gif: 120x120, 4k (2009-02-13 12:43) img3.png: 120x72, 2k (2009-02-13 12:43) img4.jpg: 88x120, 4k (2009-05-19 19:36) img11.jpg: 101x120, 4k (2009-05-19 19:34) img20.png: 120x74, 3k (2009-02-13 12:43) img42.png: 120x73, 13k (2009-05-19 19:36) img100.png: 120x120, 7k (2009-05-19 19:34)