在第一行中,$embedded_video_url
没有输出任何内容。它只是说<a class="colorbox-video cboxElement" href="">Pop Up</a>
。是因为变量$embedded_video_url
稍后在代码中定义了吗?我是否必须在第一行的h3
元素之前定义变量?
<h3 class="widget-title">Latest Video <span class="pop-up-link"><a class="colorbox-video cboxElement" href="<?php echo $embedded_video_url ?>">Pop Up</a></span></h3>
<?php
$args = array(
'numberposts' => '1',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-video'
)
),
'meta_query' => array(
array(
'key' => 'dt_video',
'value' => '',
'compare' => '!='
)
)
);
$latest_video = wp_get_recent_posts($args); // Get latest video in 'video' post format
$latest_video_id = $latest_video['0']['ID']; // Get latest video ID
$video_url = "http://www.youtube.com/watch?v=l4X2hQC32NA&feature=g-all-u&context=G258729eFAAAAAAAAHAA?rel=0";
$search = '#(?:href="https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch?.*?v=))([\w\-]{10,12}).*$#x';
$replace = "www.youtube.com/embed/$1";
preg_match_all($search, $video_url, $matches);
$embedded_video_url = preg_replace($search, $replace, $video_url) ;
echo '<iframe width="180" height="101" src="'.$embedded_video_url.'" frameborder="0" allowfullscreen></iframe>';
?>
答案 0 :(得分:3)
是。您应该在使用变量之前定义/初始化变量。如果你不是,他们将是空的。如果您将第一行向下移动到底部,则应解决您的问题。