[英]Wordpress Pagination not working, it would not move to the next page
目前,我正在使用wp_query在博客页面上显示我的文章。 我遇到了分页问题。 将分页代码实现到我的wp_query中后(请参见下面的代码),分页将不起作用,每次我按第2页或下一页时,它仍显示为第一页。 另外,当我将分页号码和下一个按钮悬停时,它显示的链接都是相同的。
这是我的PHP代码。
<?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; ?>
希望您能启发我解决我的问题。 提前致谢。
这段代码对我有用。 尝试这个:
<?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; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.