我知道这篇帖子有点老了,但我也陷入了同样的困境,也许其他人会在这个问题上偶然发现答案。我想在文件中创建一个自定义循环index.php
我解决了使用documentation @Michael 在评论中发布。我只是把它转换成一个解决了的答案。
<?php
// set the "paged" parameter (use \'page\' if the query is on a static front page)
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$args_blog = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 9,
\'category__in\' => array( 2, 3 ),
\'paged\' => $paged
);
// the query
$the_query = new WP_Query( $args_blog );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php
// next_posts_link() usage with max_num_pages
next_posts_link( \'Older Entries\', $the_query->max_num_pages );
previous_posts_link( \'Newer Entries\' );
?>
<?php
// clean up after the query and pagination
wp_reset_postdata();
?>
<?php else: ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>