2015-08-29 48 views
0

我一直在創建自定義循環並設置每頁有多少帖子。我需要將此循環與每頁上的博客文章分開 - 因此是自定義循環。分頁不能在自定義Wordpress循環上工作

現在循環可以正常工作,但是我發現它與pagniation衝突......分頁顯示,但是當點擊'next'時頁面沒有改變。

這裏是我的循環:

<?php 
    $args = array('posts_per_page'=>12, 'post_type' =>'office'); 
    $category_posts = new WP_Query($args); 

    if($category_posts->have_posts()) : 
    while($category_posts->have_posts()) : 
    $category_posts->the_post(); 
?> 

    <div class="office-item-wrapper"> 

     <div class="office-item"> 

      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 


      </article> 

     </div> 

    </div> 

<?php endwhile; ?> 

<?php else: ?> 

    <article> 
     <h2><?php _e('Sorry, nothing to display.', 'html5blank'); ?></h2> 
    </article><!--/ Article --> 

<?php endif; ?> 

在此先感謝任何人誰也許能夠幫我解決這個問題:-)

回答

0

在WP,分頁由GET變量下發page,只需將其添加到詢問參數:

$page = get_query_var('paged'); 
$args = array('posts_per_page'=>12, 'post_type' =>'office', 'paged'=>$page); 

我建議你使用get_query_var('paged'),因爲如果它是空的它會送你到t他第一頁。

注:在一些主題,頁碼在page鍵發送,因此與pagepaged嘗試。

+0

感謝您的回答。我將如何在上述代碼中實現這一點? – Charly

+0

不客氣。然後選擇我的答案作爲答案。只需複製並粘貼我的代碼並替換您的$ args行 – Skatox

相關問題