WP-PageNavi在自定义页面上无法正常工作

问题描述:

我创建了一个自定义页面,该页面仅显示来自特定类别的帖子,而且我还设置wordpress以显示仅4个帖子。现在的问题是WP-PageNavi工作不正常。这是代码。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> 

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

请添加此

wp_reset_query(); 

下面

wp_pagenavi(); 

希望它做工精细

+0

http://wordpress.stackexchange.com/questions/9576/wp-pagenavi-with-custom-wp-query – Corlax

+0

你好我尝试添加您的解决方案,并提供以下食品和它的工作。只是一个问题,“wp_reset_query();函数是什么,我仍然是PHP和wordpress编码的新手,我在中尝试了这一行代码,它似乎并不工作 – clestcruz

+0

如果(have_posts()):while(have_posts()):the_post();?>你会在哪里得到(?)从特定类别ID 3现在你看到你添加pagenavigation之后wp_rese_query恢复你的查询,因此你的wp_pagenavi();不工作,所以你可以添加查询后..... .....所以你需要的所有细节http:// codex.wordpress.org/Function_Reference/wp_reset_query – Corlax

Wp_page导航需要query_post功能的 '分页' 的说法

去这个链接

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

和ctrl + f word'paged'他们,你会得到你的问题的答案。

可能会有所帮助。

<?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(); ?>