added ORDER BY to gallery query

fixes #1814