Basically what I am trying to do here is: Display the youtube thumbnail. If no youtube thumbnail -> Display the Featured image for the post. If no featured image -> Display the fallback image.
However it seems I am doing something wrong because the webpage displays blank.
<?php
// Check if the post has a Youtube thumbnail (using custom field video_url)
if get_post_meta($post->ID,'video_url',true)
echo '<img src="http://img.youtube.com/vi/' . get_post_meta($post->ID,'video_url',true) . '/0.jpg"/>';
// Check if the post has a Post Thumbnail assigned to it
else ( has_post_thumbnail() ) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail('frontpage-thumb');
echo '</a>';
// If the post does not have a featured image then display the fallback image
} else {
echo '<a href="' . get_permalink($post->ID) . '" ><img src="'. get_stylesheet_directory_uri() . '/img/fallback-featured-image-index.jpg" /></a>';}
?>
The general code for displaying the youtube thumbnail with custom fields is <img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID,'video_url',true);?>/0.jpg"/>
I just can’t get it to work with the conditional statements…
In your first
if
condition, you have wrong syntax and the PHP must be closedCorrect code