2013-04-14 103 views
0

夥計們!我試圖在每頁5篇文章中對帖子進行分頁。但我正在使用WP_Query。你能指出我在哪裏可以獲得信息來完成它嗎?謝謝。WP_Query帖子分頁

<?php $preNewsPosts = new WP_Query(); 
    $preNewsPosts->query('category_name=news&posts_per_page=30'); 
    while($preNewsPosts->have_posts()): $preNewsPosts->the_post(); 
    ?> 
    <a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail('thumbnail'); ?></a> 
    <hr style="width: 95%; border: 1px solid #e6e6e6; " /> 
    <?php 
    endwhile; 
    ?> 

回答

0

這裏是one article詳細解釋如何完成自定義WP_Query的分頁。

基本上你修改代碼,以便它看起來是這樣的:

<?php 
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    $preNewsPosts = new WP_Query(); 
    $preNewsPosts->query('category_name=news&posts_per_page=30&paged=' . $paged); 
    while($preNewsPosts->have_posts()): $preNewsPosts->the_post(); 
    ?> 
     <a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail('thumbnail'); ?></a> 
     <hr style="width: 95%; border: 1px solid #e6e6e6; " /> 
    <?php 
    endwhile; 
    ?> 

<div class="navigation"> 
    <div class="next-posts"><?php next_posts_link('&laquo; Older Entries', $preNewsPosts->max_num_pages) ?></div> 
    <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;', $preNewsPosts->max_num_pages) ?></div> 
</div>