Actually, I think you don’t need too much like above on this
For example, a loop you use to retrieve pages,
$args = array(
'posts_per_page' => 5,
'post_type' => 'page',
'paged' => $paged,
);
$the_query = new WP_Query( $args );
?>
<!-- the loop etc.. -->
Then get the paginate links
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages //The custom WP_Query instance
) );
?>