Pagination function in wordpress for posts
Put this code in functions.php file
<?php
if ( ! function_exists( 'wp_pagination' ) ) :
function wp_pagination() {
global $wp_query;
$int_val= 99999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $int_val, '%#%', esc_url( get_pagenum_link( $int_val) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
endif;
?>
and put this code anywhere for pagination
<?php wp_pagination (); ?>
<?php
if ( ! function_exists( 'wp_pagination' ) ) :
function wp_pagination() {
global $wp_query;
$int_val= 99999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $int_val, '%#%', esc_url( get_pagenum_link( $int_val) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
endif;
?>
and put this code anywhere for pagination
<?php wp_pagination (); ?>