首先,您需要将第一个循环中要在第二个循环中排除的帖子的ID保存到一个数组中,并使用该数组排除帖子。此外,始终在查询后重置post数据。
这是经过修改的代码。
<div class="row">
<?php $args = array(
\'posts_per_page\' => 1,
\'offset\' => 1,
\'category\' => \'\',
\'category_name\' => \'\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'include\' => \'\',
\'exclude\' => \'\',
\'meta_key\' => \'\',
\'meta_value\' => \'\',
\'post_type\' => \'prosjekter\',
\'post_mime_type\' => \'\',
\'post_parent\' => \'\',
\'author\' => \'\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true
);
$posts_array = get_posts( $args );
foreach ($posts_array as $row) {
$exclude[] = get_the_ID(); // Save The Post ID in an array
?>
<div class="col-lg-12">
<?php the_post_thumbnail() ?>
</div>
<?php
}
wp_reset_postdata();
?>
</div>
<div class="row">
<?php $args2 = array(
\'posts_per_page\' => 5,
\'offset\' => 2,
\'tag\' => \'\',
\'category\' => \'\',
\'category_name\' => \'\',
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'include\' => \'\',
\'exclude\' => \'\',
\'meta_key\' => \'\',
\'meta_value\' => \'\',
\'post_type\' => \'prosjekter\',
\'post_mime_type\' => \'\',
\'post_parent\' => \'\',
\'author\' => \'\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true,
\'post__not_in\' => $exclude //Exclude the IDs
);
$posts_array2 = get_posts( $args2 );
foreach ($posts_array2 as $row2) {
?>
<div class="col-lg-6">
<?php the_post_thumbnail() ?>
</div>
<?php
}
wp_reset_postdata();
?>
EDIT: 由于您只排除最新的帖子,您可以尝试
offset
参数也在第二个循环中。