can somebody tell me why this code give me url like : “http://localhost/page/1215752191/” and not url like “http://localhost/page/2/” ?
this is the code:
function mytheme_paginate() {
global $paged, $custom_query;
$big = 99999999999;
$args = array (
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '/page/%#%',
'current' => max( 1, get_query_var( 'paged' )),
'total' => $custom_query->max_num_pages,
'show_all' => False,
'end_size' => 2,
'mid_size' => 2,
'prev_next' => True,
'prev_text' =>__( '<' ),
'next_text' =>__( '>' ),
'type' => 'list'
);
echo paginate_links( $args );
}
In the index.php I have a custom loop and the code here looks like this:
<?php
$custom_query_args = array(
'posts_per_page' => 2,
'category_name' => 'news',
);
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
// Output custom query loop
if ( $custom_query->have_posts() ) :
while ( $custom_query->have_posts() ) :
$custom_query->the_post();
the_content();
endwhile;
endif;
// Reset postdata
wp_reset_postdata();
// Custom query loop pagination
mytheme_paginate();
// Reset main query object
$wp_query = NULL;
$wp_query = $temp_query;
?>