I'm developing custom WordPress theme, in that, i'm using custom queries for fetching data and also using pagination for the bulk data. I have written code for pagination and it is also showing pagination below posts. my concern is: whenever I click on 2 page (Pagination), it is showing the same post of page 1 (Pagination).
Please check with below code for your reference:-
<div class="blog_area container"> <div class="wrapper row"> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'video', 'order' => 'ASC', 'posts_per_page' => 1, 'paged' => $paged ); $the_query = new WP_Query($args); // The Query while ($the_query->have_posts()): $the_query->the_post(); $vdoLink = simple_fields_value('vdo_link'); $showVdo = $vdoLink; ?> <div class="main_wrapper col-lg-12 col-md-12 row_wrapper"> <div class="col-md-6"> <div class='embed-container'> <iframe src="<?php echo $showVdo; ?>" frameborder="0" allowfullscreen></iframe> </div> </div> <div class="col-md-6"> <div class="row "> <h2 class="margin-top-zero"> <b><?php the_title(); ?></b> </h2> </div> <div class='row'> <p><?php the_content('Read More'); ?></p> </div> </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 ) ) ), 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $the_query->max_num_pages )); ?> </div> </div </div> </div>
you can try this code.
<?php
$args = array(
'order' => 'DESC',
'showposts' => 1,
'post_type' => 'video',
'paged' => $paged
);
$the_query = new WP_Query($args);
// The Query
if($the_query->have_posts()) : while($the_query->have_posts()): $the_query->the_post(); ?>
<?php the_title(); ?>
<?php
wp_reset_query();
endwhile; else :
echo "no posts!";
endif;
?>
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
// 'base' => str_replace( $big, '', esc_url( get_pagenum_link( $big ) ) ),
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
));
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.