我正在构建我的第一个主题,并有一个模板页;页面博客;使用自定义wp\\U查询。我尝试向查询添加分页,但到目前为止,分页会重定向到索引页。正如所料,url结构显示为/blog/page/2。
我做错了什么?我需要创建自己的分页方法吗?
<div class="blog-listings">
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'blog\',
\'post_status\' => \'publish\',
\'posts_per_page\' => \'2\',
\'paged\' => $paged,
\'orderby\' => \'date\',
);
$blog_loop = new WP_Query( $args );
if ($blog_loop->have_posts()) :
while ($blog_loop->have_posts()) : $blog_loop->the_post();
include(\'template-parts/content/content-single-blog.php\');
endwhile;
$total_pages = $blog_loop->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var(\'paged\'));
echo paginate_links(array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'format\' => \'/page/%#%\',
\'current\' => $current_page,
\'total\' => $total_pages,
\'prev_text\' => __(\'prev\'),
\'next_text\' => __(\'next\'),
));
}
wp_reset_postdata();
endif;
?>
</div>