If I post an article and define several categories, in this case all that are in the loops, the only post that will appear will be the one, because it is the last one.
What I want is that the last post of each category appears without repeating, if the last post is in several categories, then I want it to show the penultimate one.
With $do_not_duplicate[] = $post->ID; does not work
How the posts are appearing:
Code:
<?php $page = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'page' => $page, 'cat' => 'cat=2 ' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="intro-noticia-1">
<a href="<?php the_permalink(); ?>">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="intro-post-thumbnail" style="background: url('<?php echo $backgroundImg[0]; ?>'); background-size: cover; background-position: center;">
</div></a>
</div>
<?php endwhile; ?>
<?php $page = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'page' => $page, 'cat' => 'cat=3 ' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="intro-noticia-2">
<a href="<?php the_permalink(); ?>">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="intro-post-thumbnail" style="background: url('<?php echo $backgroundImg[0]; ?>'); background-size: cover; background-position: center;">
</div></a>
</div>
<?php endwhile; ?>
<?php $page = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'page' => $page, 'cat' => 'cat=4 ' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="intro-noticia-3">
<a href="<?php the_permalink(); ?>">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="intro-post-thumbnail" style="background: url('<?php echo $backgroundImg[0]; ?>'); background-size: cover; background-position: center;">
</div></a>
</div>
<?php endwhile; ?>
<?php $page = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'page' => $page, 'cat' => 'cat=5 ' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="intro-noticia-4">
<a href="<?php the_permalink(); ?>">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="intro-post-thumbnail" style="background: url('<?php echo $backgroundImg[0]; ?>'); background-size: cover; background-position: center;">
</div></a>
</div>
<?php endwhile; ?>
<?php $page = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 1, 'page' => $page, 'cat' => 'cat=6 ' );
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); $do_not_duplicate[] = $post->ID; ?>
<div class="intro-noticia-5">
<a href="<?php the_permalink(); ?>">
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="intro-post-thumbnail" style="background: url('<?php echo $backgroundImg[0]; ?>'); background-size: cover; background-position: center;">
</div></a>
</div>
<?php endwhile; ?>
$do_not_duplicate
but then you're not doing anything with that array to exclude them from the other queries.