0

我创建了一个自定义页面,它将仅显示来自特定类别的帖子,并且我还设置wordpress为仅显示 4 个帖子。现在的问题是它WP-PageNavi不能正常工作。这是代码。

<div class="sixteen columns latest_post">

<?php query_posts('cat=3', 'posts_per_page=-1=-'); if(have_posts()) : while(have_posts()) :the_post(); ?>
   <div class="sixteen columns alpha omega outer_box">
       <div class="inner_box articles">

           <!--TITLE OF THE POST -->
           <h3 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>



           <ul class="data">
             <li><?php the_author_posts_link() ?> /</li>
             <li><?php the_category(', ') ?> /</li>
             <li><?php the_time('F jS, Y') ?> /</li>
             <li><?php comments_number() ?></li>
           </ul>

           <hr>

           <!--THUMBNAIL -->
           <div class="align_thumbnail_right">
              <?php if ( has_post_thumbnail()) the_post_thumbnail('home-thumb'); ?>

           </div>

           <div class="content">
              <!--TEXT -->
              <?php the_excerpt(); ?>


             <a href="<?php echo get_permalink(); ?>"><span>Read More</span></a>
           </div>

        </div>

   </div>

<?php endwhile; endif; wp_reset_query();?>

<!--PAGINATION -->

<div class="pagination">
<?php wp_pagenavi(); ?>
</div>

我在索引页面上应用了插件,它似乎工作正常。但是当我在自定义页面上尝试它时它不起作用。

4

3 回答 3

2

Wp_page navi needs a 'paged' argument in query_post function

go to this link

http://codex.wordpress.org/Function_Reference/query_posts

and ctrl+f word 'paged' their, you'll get the answer of your question.

may be it helps.

于 2013-06-20T08:00:06.670 回答
1

请添加这个

wp_reset_query();

以下

wp_pagenavi();

希望它工作正常

于 2013-06-20T07:31:17.243 回答
-1
<?php
$temp = $wp_query;
$wp_query= null;
$args = array(
  'post_type'     =>  'post',
  'post_status'   =>  'publish',
  'posts_per_page'  =>  3,
  'orderby' => 'id',
  'order' => 'desc',
  'paged' => $paged
);  

$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
  // do something
endwhile;

if(function_exists('wp_pagenavi')) { 
  echo '<div class="pagination">';
  wp_pagenavi();
  echo '</div>';
}
$wp_query = null; $wp_query = $temp;
wp_reset_query(); ?>
于 2016-08-16T09:48:54.647 回答