Custom Post Pagination
How to Add Pagination in Custom Post
This is a simple tricks but very important to know how to add WordPress pagination in custom post.
We know that to use custom post must need to post query by using loop. Normally the custom post query look like this:
<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=6&post_type=your_custom_post_type'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <!--Here goes to post HTML with dynamic php--> <?php endwhile; ?> <?php $wp_query = null; $wp_query = $temp; // Reset ?>
When we need pagination for custom post than the code will be look like this.
<?php $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query('showposts=6&post_type=your_custom_post_type'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <!--Here goes to post HTML with dynamic php--> <?php endwhile; ?> <nav> <?php previous_posts_link('« Newer') ?> <?php next_posts_link('Older »') ?> </nav> <?php $wp_query = null; $wp_query = $temp; // Reset ?>
If you need to style this, can take ID or class easily by using span tag. Hopefully working good this if face any problem to use custom post pagination comment here.
Comments are closed