I have created custom theme in Wordpress. I want to add custom pagination to my custom post template which is INDEX.PHP
Can you please check what is wrong in pagination script. actually i have set 4 post limit and there around 8 posts in my blog.. when click on 2 pagination, it won't move to next page...
<?php get_header(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// WP_Query arguments
$args = array (
'post_type' => the_post(),
'posts_per_page' => '3',
'paged' => $paged
);
?>
<?php
// The Query
$cquery = new WP_Query( $args );
while ( $cquery->have_posts() ) : $cquery->the_post();
?>
<div class="row">
<div class="img"><a href="<?php the_permalink() ?>" class="imgPos"><?php the_post_thumbnail('full'); ?></a></div>
<div class="text">
<h2><a href="<?php the_permalink() ?>" style="color:#545454;"><?php the_title(); ?></a></h2>
<h3 style="line-height: 1px;"><span class="floatL">By </span> <span class="floatL"> <?php the_author_posts_link(); ?> </span> <span class="floatL"> - </span> <span class="floatL"><?php the_time('F jS, Y'); ?></span><div class="clr"></div></h3>
<p><?php the_content('Read More') ?></p>
</div>
</div>
<?php
$post->ID;
endwhile;
$big = 999999999; // need an unlikely integer
?>
<div class="row">
<div class="pagination">
<?php
echo paginate_links( array(
'base' => str_replace( $big, '', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $cquery->max_num_pages
) );
?>
</div>
</div>
<?php get_footer(); ?>
Try this
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
// WP_Query arguments
$args = array (
'post_type' => 'YOUR_CUSTOM_POST_TYPE',
'posts_per_page' => '3',
'paged' => $paged
);
// The Query
$cquery = new WP_Query( $args );
while ( $cquery->have_posts() ) : $cquery->the_post();
echo $post->ID;
endwhile;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $cquery->max_num_pages
) );