我一直致力于创建自定义循环并设置每页的帖子数量。我需要将此循环与每页的博客帖子分开 - 因此是自定义循环。
现在循环确实有效,但是我注意到它与pagniation有冲突...分页显示但是当你点击下一个'时页面没有变化。
这是我的循环:
<?php
$args = array('posts_per_page'=>12, 'post_type' =>'office');
$category_posts = new WP_Query($args);
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<div class="office-item-wrapper">
<div class="office-item">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
</article>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article><!--/ Article -->
<?php endif; ?>
提前感谢任何可以帮助我解决此问题的人: - )
答案 0 :(得分:2)
在WP中,分页由GET
下的page
变量发送,只需将其添加到查询参数中:
$page = get_query_var('paged');
$args = array('posts_per_page'=>12, 'post_type' =>'office', 'paged'=>$page);
我建议您使用get_query_var('paged')
,因为如果它为空,则会将您发送到第一页。
注意: 在某些主题中,页码是通过page
密钥发送的,因此请尝试使用page
或paged
。