2017-07-07 111 views
2

我創建了一個分頁循環,每頁顯示三篇文章。分頁只顯示兩頁的帖子,而它應該顯示四頁,因爲共有11篇文章。我使用的代碼來自WordPress Codex。我只是剛剛開始使用WordPress開發和PHP,所以我的知識仍然很基礎。任何幫助,將不勝感激。這是我的時刻:wordpress循環與分頁只顯示兩頁

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$args = array(
    'posts_per_page' => 3, 
    'paged' => $paged 
); 

$the_query = new WP_Query($args); 
?> 

<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 
    <p><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p> 
<?php endwhile; ?> 

<!-- pagination --> 
<?php next_posts_link(); ?> 
<?php previous_posts_link(); ?> 

<?php else : ?> 
<!-- No posts found --> 
<?php endif; ?> 

回答

-1

嘗試從查詢中移除posts_per_page和設置此次在「博客頁面顯示在最」中設定的閱讀區部分。

然後在你的next_post_link(),添加以下條件,所以它看起來是這樣的:

next_posts_link('Next Page »', $the_query->max_num_pages); 

注意,第一個參數可以說任何你想要的話。第二個參數是允許分頁正常工作的原因。希望這可以幫助。