How To display Pagination with Custom Blog Post

here is code to display pagination on custom blog teplate


<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 5,
'paged' => $paged,
'post_type' => 'post'
);
$cpt_query = new WP_Query($args);
if ($cpt_query->have_posts()) : while ($cpt_query->have_posts()) : $cpt_query->the_post();
the_title();
the_content();
endwhile; endif;

  • <?php
    previous_posts_link( ‘« PREV’, $cpt_query->max_num_pages) ?>
  • <?php
    next_posts_link( ‘NEXT »’, $cpt_query->max_num_pages) ?>

Advertisements

One thought on “How To display Pagination with Custom Blog Post

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s