2013-06-20 53 views
0

我創建了一個自定義頁面,該頁面僅顯示來自特定類別的帖子,而且我還設置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> 

我在插入頁面上應用了插件,它似乎工作正常。但是當我在自定義頁面上嘗試它時,它不起作用。

回答

1

請添加此

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編碼的新手,我在<?php endwhile; endif?>中嘗試了這一行代碼,它似乎並不工作 – 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

0
<?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(); ?> 
相關問題