I guess nobody knows the answer ?? So I spent few hours coding and now I got modified function which does that and here it is:
/**
* Built-in pagination for galleries
* Mod by SoWhat
* @since 1.6.5.1
*/
function file_gallery_do_pagination( $max_num_pages = 0, $page = 0 )
{
$max_count = $max_num_pages;
if( 0 < $max_num_pages && 0 < $page )
{
$out = array();
remove_query_arg('page');
if ($max_count <= 10 || $page > $max_num_pages-10) { // if less then 10 pages or in the end
$ix=0;
while( 0 < $max_num_pages)
{ if ($ix > 10 && $page > $max_num_pages-10) break;
if( (int) $page === (int) $max_num_pages )
$out[] = '<span class="current">' . $max_num_pages . '</span>';
else
$out[] = str_replace('<a ', '<a class="page"', _wp_link_page($max_num_pages)) . $max_num_pages . '</a>';
$max_num_pages--; $ix++;
}
if ($max_count > 10) return '<div class="wp-pagenavi">' . "\n<a href='../1/'>1</a> .. ". implode("\n", array_reverse($out)) . "\n" . '</div> ';
else return '<div class="wp-pagenavi">' . "\n". implode("\n", array_reverse($out)) . "\n" . '</div> ';
} elseif ($page < 10) { //in the beginning
$ix=0;
while( 0 < $max_num_pages)
{
if( (int) $page === (int) $max_num_pages )
$out[] = '<span class="current">' . $max_num_pages . '</span>';
else
if ($max_num_pages <= 10) $out[] = str_replace('<a ', '<a class="page"', _wp_link_page($max_num_pages)) . $max_num_pages . '</a>';
$max_num_pages--; $ix++;
}
return '<div class="wp-pagenavi">' . "\n". implode("\n", array_reverse($out)) . " .. <a href='../$max_count/'>$max_count</a>\n" . '</div> ';
} else { //in the middle
for ($max_num_pages = $page + 5; $max_num_pages>=$page - 5 ; $max_num_pages--) {
if( (int) $page === (int) $max_num_pages )
$out[] = '<span class="current">' . $max_num_pages . '</span>';
else
$out[] = str_replace('<a ', '<a class="page"', _wp_link_page($max_num_pages)) . $max_num_pages . '</a>';
}
return '<div class="wp-pagenavi">' . "\n<a href='../1/'>1</a> .. ". implode("\n", array_reverse($out)) . " .. <a href='../$max_count/'>$max_count</a>\n" . '</div> ';
}
}
return '';
}
In case you want to use it, it works only with url-rewriting enabled and it is for plugin version 1.6.5.4. It is located in /file-gallery/includes/templating.php at line 310.
PS. I am a beginner in PHP and it is very late here, so code probably could be more optimised and you are welcome to do that ??
PPS. Plugin developers, please include this (or similar) script in next plugin releases.