WP-Page Navi不起作用

时间:2018-01-22 09:50:52

标签: wordpress

如何解决这个问题?我真的不知道。  插件仅生成此html:

<div class="wp-pagenavi">
  <span class="pages">Page 1 of 1</span><span class="current">1</span>
</div>

这是我的archive.php

   <?php $loop = new WP_Query(array(  'orderby' => 'ASC',  )); ?> 
    <?php if($loop->have_posts() ) :  ?> 

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

    <article class="article">
        <div class="time"><?php the_time('Y-m-d'); ?></div>
        <div class="h2"><?php the_title(); ?></div>
        <div class="article__descript">
            <?php $content = the_content();
            $test =substr($content, 0, 20);
            echo $test; ?>
        </div>
    </article>

    <?php endwhile; ?>
    <?php wp_pagenavi(); wp_reset_query(); ?>
    <?php else : ?> 
    <?php endif;  ?>

1 个答案:

答案 0 :(得分:1)

试试这个。我已经更新了你的代码 - 您尚未在查询参数中传递参数paged

<?php 

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

 $loop = new WP_Query(array('post_type' => 'post',
                                    'paged' => $paged,
                                    'posts_per_page' => 5,
                                    'orderby' => 'date',
                                    'post_status'=>'publish'                               
                                    ));
 ?> 
    <?php if($loop->have_posts() ) :  ?> 

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

    <article class="article">
        <div class="time"><?php the_time('Y-m-d'); ?></div>
        <div class="h2"><?php the_title(); ?></div>
        <div class="article__descript">
            <?php $content = the_content();
            $test =substr($content, 0, 20);
            echo $test; ?>
        </div>
    </article>

    <?php endwhile; ?>
    <?php wp_pagenavi(); wp_reset_query(); ?>
    <?php else : ?> 
    <?php endif;  ?>