<?php
$featured_posts = get_field('director');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $featured_post ):?>
<div class="movies-series-director">
<a class="movies-series-director-thumbnails" href="<?php echo get_page_link($featured_post->ID);?>"> <img src="<?php echo get_the_post_thumbnail_url($featured_post->ID, 'thumbnail');?>"></a>
<div class="movies-series-director-title">
<h4> <a href="<?php echo get_page_link($featured_post->ID);?>"> <?php echo $featured_post->post_title;?> </a> </h4>
<b>Director</b>
</div>
</div>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Guys how to output like this.
If has thumbnail then post thumbanil
else if no thumnail then print this this image (no image)
2
Answers
Here is your working code:
You want to check if the thumbnail is empty, and if there is no thumbnail, display a default image.
So you use
get_the_post_thumbnail_url()
and check if it is empty.If you like it a bit more readable, your code can look like: