2016-10-07 108 views
0

這個wordpress主題的分頁我正在編碼,似乎沒有工作,任何一個有更好的理想?先謝謝你。WordPress分頁不起作用

下面是我的完整代碼,我有點困惑,曾嘗試使用插件並調用短代碼wp-pagenavi但它不工作,我會很感激任何幫助。

<?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $args = array('post_type' => 'post', 'posts_per_page' => 10, 'paged' => $paged); 
    $query = new WP_Query($args); 
    if($query->have_posts()) : 
    while($query->have_posts()) : $query->the_post(); ?> 
    <div class="media"> 
    <div class="media-left"> 
    <div class="hovereffect"> 


     <a href="#"><?php the_post_thumbnail();?></a> 
     <div class="overlay"> 
      <h2>Share</h2> 
      <p class="icon-links"> 
       <a href="#"> 
        <span class="fa fa-twitter"></span> 
       </a> 
       <a href="#"> 
        <span class="fa fa-facebook"></span> 
       </a> 
       <a href="#"> 
        <span class="fa fa-instagram"></span> 
       </a> 
      </p> 
     </div> 

    </div> 
    </div> 
    <div class="media-body"> 
     <h4 class="media-heading"><?php the_title()?></h4> 
     <p class="media-author"><b><?php the_author()?></b> - <?php echo get_the_date(); ?></p> 
      <?php the_content();?> 
     </div> 
    </div> 
    <?php endwhile;?> 
<!-- pagination --> 
<?php next_posts_link(); ?> 
<?php previous_posts_link(); ?> 
<?php else : ?> 
<!-- No posts found --> 
<?php endif; ?> 

回答

0

你必須使用$query->max_num_pagesnext_posts_link第二個參數,你可以看到here

// next_posts_link() usage with max_num_pages 
next_posts_link('Older Entries', $the_query->max_num_pages); 
previous_posts_link('Newer Entries'); 
+0

可選參數, – naththedeveloper

+0

我知道,但它是一個自定義查詢,並有必要 –

+0

先生您好,我抱歉購買,似乎沒有工作 –