PRECONDITION:
- I created post type ‘comparison’.
- I created archive page for ‘comparison’ post type only.
TASK: I need to create pagination at archive page of ‘comparison’.
PROBLEM: I tried to use
<?php echo paginate_links(); ?>
but it doesn’t work, pls help.
Advertisement
Answer
Try the following code
$query = new WP_Query( array( 'posts_per_page'=>30, 'post_type'=>'comparison', 'paged' => get_query_var('paged') ? get_query_var('paged') : 1 ) ); ?> <?php while ($query -> have_posts()) : $query -> the_post(); ?> //your code endwhile; $total_pages = $query->max_num_pages; if ($total_pages > 1){ $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $query->max_num_pages ) ); } wp_reset_postdata();