您可以检查主循环中的迭代$wp_query->current_post
while( have_posts() ){
the_post();
the_title();
// count starts at zero, so after 1 will be after 2nd post
if( 1 == $wp_query->current_post ){
the_widget( \'WP_Widget_Recent_Posts\' );
}
}
编辑关于捕获小部件输出的评论,您可以尝试PHP输出缓冲:
ob_start();
the_widget( \'WP_Widget_Recent_Posts\' );
$widget_output = ob_get_clean();