如果我发布了一篇文章并定义了几个类别,在这种情况下,循环中的所有内容都会出现,唯一会出现的帖子就是那篇,因为它是最后一篇。
我想要的是,每个类别的最后一篇文章都不会重复出现,如果最后一篇文章分为几个类别,那么我希望它显示倒数第二个类别。
使用$do\\U not\\U duplicate[]=$post->ID;不起作用
帖子的显示方式:
代码:
<?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; ?>