How to query custom post with pagination
Md Abul Bashar | 5,564 views | February 4, 2016 | Tips And Tricks,WordPress Themes Development | 2 | 7:44 AM |
Hello, Today i will teach you how to query any custom post with pagination in your WordPress theme,
You can see below code
<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=6&post_type=posttype&orderby=menu_order&order=ASC'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> // Your Contents <?php endwhile; ?> <?php if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { include('navigation.php'); } ?> <?php $wp_query = null; $wp_query = $temp; // Reset ?>
and Now you can use WP-PageNavi Plugin or you can create navigation.php page then past below code in your navigation.php page
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div>
or you can remove this code above query code
<?php if (function_exists('wp_pagenavi')) { wp_pagenavi(); } else { include('navigation.php'); } ?>
and input this code
<?php the_posts_pagination(array( 'screen_reader_text' => ' ', 'end_size' => 2, 'mid_size' => 4, ));?>
If you use this code then you can see numbering pagination.
You have to enjoy this articel? Don't forget subscribes this site.
If you want to get our update article, then please subscribe this site.
Hey Abul Bashar, Thanks for sharing this great tutorial as i am doing the pagination work from the tutorial https://www.wpblog.com/use-wp_query-to-create-pagination/ but still having issues in the code . Can you please let me know where i am doing mistake.
4,
‘paged’ => $paged
);
$custom_query = new WP_Query( $args );
?>
have_posts()) :
$custom_query->the_post();
?>
<a href="” >
<a href="”>
max_num_pages);
} ?>
<?php get_footer();
Thanks for comment, please let me know your full code in pastebin.com