By default, WordPress uses next and previous links which allow you to go one page at a time. It (wp pagination) just produces next and previous links. But the truth is, this type of pagination is not enough (even good) for website/blog (maximum time). So if you want to add a numbered pagination in your site, the blow function is best for you.

Add this code to your theme’s functions.php file:

// Numbered Pagination
function numbered_pagination(){
    global $wp_query;
    $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' => $wp_query->max_num_pages
    ));
}

Then place this code where you want to show the pagination (example on archives.php, index.php) :

<?php numbered_pagination(); ?>

It’ll produce a row HTML version of pagination. Now you can stylize the pagination with CSS/SASS.

Tags: