Currently, I'm using wp_query to display my articles on the blog page, however. I got into a problem with paginations. after implementing the pagination code into my wp_query (Please see code below), the pagination would not work, everytime I press page 2 or next page it still show's the first page. Also, when I hover the pagination numbers and next button it shows the links are all the same.
Here's my php code.
<?php
$args = array('post_status' => 'publish');
$wp_query = new WP_Query($args);
$big = 99999999999999;
if($wp_query->have_posts()) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<a href="<?php echo the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
<p><?php the_post_thumbnail( 'large', array( 'class' => 'img-responsive' )); ?></p>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?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' => $wp_query->max_num_pages
) );
?>
<?php endif; ?>
Hopefully, you can enlighten me about my problem. Thanks in advance.
This code is working for me. Try this:
<?php
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array('post_status' => 'publish','paged' => $paged);
$wp_query = new WP_Query($args);
$big = 99999999999999;
if($wp_query->have_posts()) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<a href="<?php echo the_permalink() ?>"><h2><?php the_title(); ?></h2></a>
<p><?php the_post_thumbnail( 'large', array( 'class' => 'img-responsive' )); ?></p>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?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' => $wp_query->max_num_pages
) );
?>
<?php endif; ?>
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.