There is lots of developers who actually didn’t know how to use pagination in WordPress posts. So many people are in this field are using plugin for WordPress posts pagination but they didn’t realize that plugin makes website heavy so if pagination can work by using some functions then why should we use plugin so let me tell you that how to use pagination in wordpress post without having any plugin. Lets start with some codes.
1) Use this method for default posts
Use this code into your fucntion.php file
if ( ! function_exists( 'post_pagination' ) ) : function post_pagination() { global $wp_query; $pager = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $pager, '%#%', esc_url( get_pagenum_link( $pager ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); } endif;
After doing this call the pagination function where you want to display the pagination.
<?php post_pagination(); ?>
you have to set post limit from WordPress backend for this you have to go to Settings >> Reading >> Select number of posts you wish to display.
2) Use this method for custom posts
All the methods should be the same but when you are using custom post type you have to use this loop for pagination.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 'post', // You can add a custom post type if you like 'paged' => $paged, 'posts_per_page' => 10 // limit of posts )); if ( have_posts() ) : while ( have_posts() ) : the_post(); // post content goes here... endwhile; post_pagination(); else : // no posts found message goes here... endif;
By using this you can get pagination for WordPress posts without any plugin and your website will be load free. Hope this tutorial will be helpful to you and if you face any problem or you have any suggestion we welcomes you always.
Good Luck !
Nice artical…thanks
This is really a great stuff for sharing. Keep it up. Thanks for sharing.
I appreciate your efforts in preparing this post. I really like your blog articles.
Awesome, Thanks for contributing your important time to post such an interesting & useful collection of knowledgeable resources that are always of great need to everyone. I visit this blog first time and encourage by this good stuff work. Unbelievable post keeps up posting such great information. There are things here that I didn’t think some time as of late. am very enjoyed for this weblog. It’s an informative subject matter.
The park is also famous for hosting some of the delicious eateries with of course a verse range of food items key west florida resorts
Your site is truly cool and this is an incredible moving article. Much obliged to you to such an extent. run 2
Thanks for your post! I think there are many other people who are interested in them just like me! How long does it take to complete this article? I have read through other blogs, but they are cumbersome and confusing. I hope you continue to have such quality articles to share!
Good information.