According to your question, you need to take two main steps:
Step 1: Instead of 1, 2, 3, 4...Last Number
you need 1, 2, 3...19, 20, Last Number
Step 2: You need to add 0
prefix in the pagination numbering when the number is less than 10
, that is: 01, 02, 03...19, 20, Last Number
This is definitely possible using paginate_links()
function.
Solution for Step 1:
To make sure 3 pagination numbers show up from the two ends, you need to use the attribute: 'end_size' => 3
Solution for Step 2:
To make sure numbers less than 10
are prefixed with 0
, you need to use the filter hook: number_format_i18n
Final CODE:
First, place the following function somewhere in your functions.php
file:
/* Filter function to be used with number_format_i18n filter hook */
if( ! function_exists( 'wpse255124_zero_prefix' ) ) :
function wpse255124_zero_prefix( $format ) {
$number = intval( $format );
if( intval( $number / 10 ) > 0 ) {
return $format;
}
return '0' . $format;
}
endif;
Then, use the following CODE instead of the one you’ve provided in your question:
$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link,
'index.php' ) ? 'index.php/' : '';
$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%',
'paged' ) : '?paged=%#%';
add_filter( 'number_format_i18n', 'wpse255124_zero_prefix' );
/*Set up paginated links.*/
$links = paginate_links( array(
'base' => $pagenum_link,
'format' => $format,
'total' => $wp_query->max_num_pages,
'current' => $paged,
'mid_size' => 1,
'end_size' => 3,
'after_page_number' => '.',
'add_args' => array_map( 'urlencode', $query_args ),
'prev_text' => '',
'next_text' => '',
'type' => 'list'
) );
remove_filter( 'number_format_i18n', 'wpse255124_zero_prefix' );
Now you should get your expected pagination.