2015-07-02 57 views
2

如何,我可以在我的頁面啓用分頁(模板頁面的wordpress)我怎樣才能使WordPress的帖子分頁

我的代碼

<?php 
$catquery = new WP_Query('cat=2&posts_per_page=10'); 
while($catquery->have_posts()) : $catquery->the_post(); 
?> 
<div> 
    <br /> 
<div class="news"><!-- Start News Box --> 
<div class="img_news"><!-- Start Image News --> 
<?php 
$url_thumb = wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 
?> 
<img class="img_thumbs" title="" alt="" src="<?php echo $url_thumb; ?>"> 
</div><!-- End Image News --> 
<div class="title_news"><!-- Start Title News --> 
<h2> 
<?php the_title(); ?> 
</h2> 
<div class="details"> 
<?php the_content_limit(500, "Read More..."); ?> 
</div> 
</div><!-- End Title News --> 
<hr> 
</div><!-- End News Box --> 
</div> 
<?php endwhile; ?> 

我使用的這個,但我不能看到分頁巴:例如(1-2-3 -...- 100)

感謝

回答

1

您需要在參數($ catquery)中添加'paged'屬性。

$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1; 
$catargs = array('cat'=>'2','posts_per_page'=>10,'paged' => $paged); 

$catquery = new WP_Query($catargs); 
while($catquery->have_posts()) : $catquery->the_post(); 
//do stuff 
endwhile; 

$big = 999999999; 
echo paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
    'format' => '?paged=%#%', 
    'current' => max(1, get_query_var('paged')), 
    'total' => $catquery->max_num_pages, 
    'prev_text'   => __('Previous page', 'twentyfifteen'), 
    'next_text'   => __('Next page', 'twentyfifteen'), 
)); 
0

您應前或你的循環之後添加這些功能的分頁(或之前後while環路):

<div class="nav-previous alignleft"><?php next_posts_link('Older posts'); ?></div> 
<div class="nav-next alignright"><?php previous_posts_link('Newer posts'); ?></div> 

看一看WordPress的文檔here