admin管理员组文章数量:1389768
I am currently trying to implement a load more function described in this stackoverflow post, and in order to do so it is necessary to know how many post have been loaded already. Thus, I am trying to return the number of current posts in a given page.
The code in question is the following:
<div class="row">
<?php
$posts = new WP_Query(array(
'offset' => 0,
'posts_per_page' => 6
));
while ($posts->have_posts()) {
$posts->the_post(); ?>
<div class="card__wrapper col-sm-12 col-md-6 col-lg-4 ">
<?php get_template_part('partials/card', 'page'); ?>
</div>
<?php }
wp_reset_postdata(); ?>
</div>
<?php
global $wp_query;
// if ($wp_query->max_num_pages > 1)
echo '<div class="row"><div class="col-sm-12"><div class="misha_loadmore">More posts</div></div></div>'; // you can use <a> as well
?>
Even though, the WP_Query returns only 6 posts, the functions get_query_var('posts_per_page')
and $wp_query->post_count
, when called, return 10. Any ideas, what I am missing here?
Thanks in advance.
本文标签: paginationGet the number of posts shown in the current page
版权声明:本文标题:pagination - Get the number of posts shown in the current page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744623795a2616190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论