The error is because their is no specification for the 'ORDER BY'... should be between the 'ORDER BY' and the 'LIMIT 0,1' - so a variable isn't properly populated...
You didn't proved a link to your gallery - nor the version/release you are running - so it is difficult to diagnose.
V1.5.28 does not contain the failing SQL statement on line 778.
Similar SQL is constructed beginning on line 714 and executed on line 731:
$sort_array = array(
'ta' => "a.title ASC, a.aid ASC",
'td' => "a.title DESC, a.aid DESC",
'da' => "a.aid ASC",
'dd' => "a.aid DESC",
'pa' => "a.pos ASC, a.aid ASC",
'pd' => "a.pos DESC, a.aid DESC",
);
//$sort_code = isset($USER['sort'])? $USER['sort'] : $CONFIG['album_sort_order'];
//$sort_order = isset($sort_array[$sort_code]) ? $sort_array[$sort_code] : $sort_array[$CONFIG['album_sort_order']];
$sort_order = $sort_array[$CONFIG['album_sort_order']];
$sql = "SELECT a.aid, a.title, a.description, a.thumb, a.keyword, category, visibility, filepath, filename, url_prefix, pwidth, pheight, a.owner "
. " FROM {$CONFIG['TABLE_ALBUMS']} AS a "
. " LEFT JOIN {$CONFIG['TABLE_PICTURES']} AS p ON a.thumb=p.pid "
. " WHERE a.category = $cat $album_filter "
. " ORDER BY $sort_order $limit";
$alb_thumbs_q = cpg_db_query($sql);
Please provide a link and/or the version release so I can confirm the statement...
Also what value is saved in you cpg_config table with name field of 'album_sort_order'?
From a tool like phpMyAdmin, you can issue SQL:
SELECT * from `cpg_config` WHERE `name` = 'album_sort_order'
Please post results...