vendredi 20 septembre 2019

Displaying a no posts statement on my WP homepage when there are no posts to feature

I am currently featuring 2 posts on the homepage of a recruitment site - however I want to display a message on the home page when there are no opportunities (posts) available. - I cannot seem to get the if/else statements to work with the addition of the code to display 2 posts per page.

I have tried if/else however I am relatively new to php.

<?php $the_query = new WP_Query( 'posts_per_page=2' ); ?>
<?php while ($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 endwhile; wp_reset_postdata();?>                  



<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>   



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

Aucun commentaire:

Enregistrer un commentaire