我正在我的主页上显示5篇最新帖子。我正在使用一个计数,以便在第三篇文章中显示一个div,它将与博客文章完全分离。然而,在添加该分区后,第三个帖子并没有继续,而是跳过了它,转到了第四个帖子。你知道如何保持最近5篇帖子的显示,但只在第二篇帖子后添加一个div吗?
<?php $my_query = "showposts=5"; $my_query = new WP_Query($my_query); ?>
<?php if ($my_query->have_posts()) :?>
<?php $count = 0; ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>
<div id="latest-news" class="col-lg-4" style="height:480px;">
<h2>Latest News</h2>
</div>
<?php else : ?>
<div class="col-lg-4">
<article <?php post_class(\'news-post\'); ?>>
<div class="innerPost">
<a class="postLink" href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(\'full\', array( \'class\' => \'img-responsive\')); ?>
</a>
<div class="postDetails">
<div class="postDetInner">
<header>
<div class="arrowpan"></div>
</header>
</div>
</div>
</div>
<div class="news-post-inner">
<?php
$category = get_the_category();
if($category[0]){
echo \'<a class="category-link" href="\'.get_category_link($category[0]->term_id ).\'">\'.$category[0]->cat_name.\'</a>\';
}
?>
<h2 class="entry-title"><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title( $ID ); ?> </a></h2>
</div>
</article>
</div>
<?php endif; ?>
<?php endwhile; // end of one post ?>
<?php endif; //end of loop ?>
<?php wp_reset_postdata(); ?>