ok, I am modified the code and finaly get such code:
//-----NEXT IMAGE FROM OTHER CAT -------------
if (!$in_mode && !$next_image_id)
{
$sq1 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
FROM ".IMAGES_TABLE."
WHERE image_active = 1 AND cat_id > $cat_id
ORDER BY cat_id, ".$config['image_order']." ".$config['image_sort'].", image_id ".$config['image_sort']."
LIMIT 1";
if ($row = $site_db->query_firstrow($sq1))
{
$next_image_id = $row['image_id'];
$next_prev_cache[$next_image_id] = $row;
}
$site_db->free_result();
}
if (!$in_mode && !$prev_image_id)
{
if(substr($config['image_sort'],0,1)=="D") $image_prev_sort="ASC"; else $image_prev_sort="DESC";
$sq2 = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
FROM ".IMAGES_TABLE."
WHERE image_active = 1 AND cat_id < $cat_id
ORDER BY cat_id DESC, ".$config['image_order']." ".$image_prev_sort.", image_id ".$image_prev_sort."
LIMIT 1";
if ($row = $site_db->query_firstrow($sq2))
{
$prev_image_id = $row['image_id'];
$next_prev_cache[$prev_image_id] = $row;
}
$site_db->free_result();
}
//---------END--------------------------------
in the "Image settings" I have Sort images by Date.
When you reach the last image in the category in next preview, you get next thumbnail image from next category.
Please check. need to work