主页上有 2 个帖子的问题

Issue featuring 2 posts on homepage

我想在招聘网站的主页上展示 2 个帖子,当没有帖子时,我想在主页上显示一条消息,说明 "There are currently no opportunities open."

我已经设法做到了其中之一,但无法同时发挥两者的作用。

更新:如果没有帖子,我现在已经收到要显示的消息,但是主页不再有两个帖子,它只有一个....

<?php $the_query = new WP_Query( 'posts_per_page=2' ); ?>
<?php if ($the_query -> have_posts()) : $the_query -> the_post(); ?>


<div class="block-halves exec-ops" ><!--id="b-10"-->

<span class="block-content">     



<h3><a href="<?php the_permalink() ?>"><?php the_field('post_title');?></a></h3>
<span class="btm"> 

<p class="job-title"><?php the_field('job_title');?></p>
<p><?php echo excerpt(22); ?></p>
<p><a href="<?php echo get_permalink( $post->ID ); ?>"><?php the_field('cta_button_home');?></a></p>            


</span> 


</span>

</div>     

<?php else: ?>      
<div class="block-halves exec-ops" ><!--display if no posts available-->

<span class="block-content">     



<h3>There are currently no opportunities open</h3>
<span class="btm">

<p class="job-title">Submit Your CV</p>
<p>We actively search for suitable roles and select the top candidates from submitted CV's when new opportunities open up.</p>
<p><a href="<?php echo get_page_link(47); ?>">Submit</a></p>            

</span> 


</span>

</div>  


<?php endif; wp_reset_postdata();?>                  




</div><!--flex-row/end-->

以下允许确定是否存在任何帖子,如果存在则循环遍历它们:

if (!$the_query -> have_posts()):
    echo "no posts";
else:
    while($the_query -> have_posts()): $the_query -> the_post();
        // Your loop code
    endwhile;
endif;