Ending Pagination loop in PHP

You could try

'total' => min(5,$wp_query->max_num_pages),

Edit:

In the source code for paginate_links

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/general-template.php#L1922

the links are displayed in a loop with $n = 1; $n <= $total; $n++ and since %#% is replaced with $n my idea is to limit the number of displayed pagelinks by restricting $total to the minimum of 5 and $wp_query->max_num_pages. Hope this helps 😉