【发布时间】:2016-07-20 21:44:23
【问题描述】:
基本上我在这里要做的是:显示 youtube 缩略图。如果没有 youtube 缩略图 -> 显示帖子的特色图片。如果没有特色图片 -> 显示后备图片。
但是我似乎做错了什么,因为网页显示为空白。
<?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>';}
?>
显示带有自定义字段的 youtube 缩略图的一般代码是 <img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID,'video_url',true);?>/0.jpg"/> 我只是无法让它与条件语句一起使用...
【问题讨论】:
标签: php wordpress conditional