add pagination to wordpress
Sure! Here is a response:
- Open your theme's functions.php file.
- Add the following code to the functions.php file:
function custom_pagination() {
global $wp_query;
$big = 999999999;
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
));
}
Save the functions.php file.
In the template file where you want to display the pagination (e.g., archive.php, index.php), add the following code where you want the pagination to appear:
<?php custom_pagination(); ?>
- Save the template file.