[英]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.