admin管理员组文章数量:1321808
I'm trying to make a pagination for a WP_Query on a frontpage using the paginate_links() function and following the codex (). The pagination displays well after 3 posts (as I request it in the new WP_Query parameter) and when clicking on the '2' link, it leads to the /page/2 with the next three posts correctly. Yay!
The problem I'm struggling with is that on the page 2, the pagination seems stuck on the page 1 aspect : '1' is not clickable and '2' is clickable which lead to the same page we are.
Please find my code below :
<?php
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var( 'paged' );
} elseif ( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
} else { $paged = 1; }
$query = new WP_Query('posts_per_page=3&paged=' . $paged);
// Check that we have query results.
if ( $query->have_posts() ) :
// Start looping over the query results.
while ( $query->have_posts() ) :
$query->the_post(); ?>
<article class="post-content">
<div class="post_meta flex-container flex-space-between">
<h2 class="post_title"><?php the_title(); ?></h2>
<?php the_category(); ?>
</div>
<?php the_content(); ?>
</article>
<?php
endwhile;
echo paginate_links( array(
'base' => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
'total' => $query->max_num_pages,
'current' => max( 1, get_query_var( 'paged' ) ),
'format' => '?paged=%#%',
'show_all' => false,
'type' => 'plain',
'end_size' => 2,
'mid_size' => 1,
'prev_next' => false,
'add_args' => false,
'add_fragment' => '',
) );
wp_reset_postdata();
endif;
?>
What do I miss? Thanks by advance for your coming help
本文标签: wp queryWPquery pagination on frontpage
版权声明:本文标题:wp query - WP_query pagination on frontpage 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742104320a2420948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论