2016-05-23 50 views
1

我想分頁自定義帖子類型列表。此列表顯示可以,但我似乎無法使分頁鏈接顯示。WordPress分頁鏈接沒有顯示自定義帖子類型查詢

下面是代碼:爲分頁

<?php 
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

     $args = array(
      'post_type' => 'families', 
      'posts_per_page' => 9, 
      'paged'=>$paged 
     ); 

     $the_query = new WP_Query($args); 

    ?> 

    <table class="families"> 

     <tr> 
      <th class="family_head">Family Head</th> 
      <th class="address">Address</th> 
      <th class="contact_number">Contact number</th> 
     </tr> 

     <?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 

     <tr> 

      <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> 

      <td><?php the_field('residence_address'); ?></td> 

      <td class="contact_number"><?php the_field('mobile_number_1'); ?></td> 

     </tr> 

     <?php endwhile; ?> 

     <div class="navigation"> 
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div> 
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div> 
     </div> 

     <?php else: ?> 

     <?php endif; ?> 

    </table> 

其它類似的WP功能也不工作。我究竟做錯了什麼?

回答

0

我刪除了所有的分頁代碼,並重新做到了。它現在有效。看看你能否找到改變。

這裏是工作的代碼 -

<div id="main_content"> 

<div id="main_content_otherpages"> 

    <?php 

     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 

     $args = array(
      'post_type' => 'families', 
      'posts_per_page' => 20, 
      'paged' => $paged 
     ); 

     $the_query = new WP_Query($args); 

    ?> 

    <table class="families"> 

     <tr> 
      <th class="family_head">Family Head</th> 
      <th class="address">Address</th> 
      <th class="contact_number">Contact number</th> 
     </tr> 

     <?php if (have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 

     <tr> 

      <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> 

      <td><?php the_field('residence_address'); ?></td> 

      <td class="contact_number"><?php the_field('mobile_number_1'); ?></td> 

     </tr> 

     <?php endwhile; ?> 

    </table> 

    <div style="clear:none; float:left"><?php next_posts_link('&larr;Previous', $the_query->max_num_pages); ?></div> 
    <div style="clear:none; float:right"><?php previous_posts_link('Next&rarr;'); ?></div> 

    <?php wp_reset_postdata(); ?> 

    <?php else: ?> 

    <?php endif; ?> 

</div> 

+0

我不確定,但我認爲這一行 - <?php next_posts_link('← Previous',$ the_query-> max_num_pages);?> 使它成功。 – user1543784

0

我認爲這是get_query_var( '分頁'),如果您使用此代碼的問題,已檢查$分頁, 嘗試更換此

$paged = (get_query_var('page')) ? get_query_var('page') : 1;

有頁面與分頁之間的區別。 您可以閱讀更多HERE

希望,這會有所幫助。你可以問我是否可以進一步幫助你。謝謝

+0

我試圖顯示此瀏覽的網頁是不是一個靜態的頭版。即使那樣,我嘗試了你的建議。但它不起作用。 :( – user1543784

+0

你在$ paged中得到了什麼?? –

相關問題