【发布时间】:2014-08-05 09:09:48
【问题描述】:
尝试在我的新 Wordpress Youtube 利基主题中做一些事情。我的主题中有一个标签供用户输入 Youtube watch?v=xxxxxxxxxxx id。当他们输入 xxxxxxxxxxx url 时,它会输出视频,通过“循环”查询显示每个标签 16 个帖子。
工作示例here
我研究了这个 Google 开发者控制台 api 的东西...对我来说完全是胡言乱语。我正在为您将在我的网站上看到的 4 个类别使用自定义帖子类型。现在只填充“喜剧”。
新编辑:这有效。感谢所有帮助我解决这个问题的人!
<?php
$new_query = new WP_Query();
$new_query->query( array('post_type' => array( 'comedy' ), 'orderby' => 'title', 'order' => 'asc','showposts' => 16, 'paged'=>$paged ));
while ($new_query->have_posts()) : $new_query->the_post();
$url = get_post_meta ($post->ID, 'comedy_url', $single = true);
include(TEMPLATEPATH . '/library/variables.php');
$code = 'http://www.youtube.com/watch?v=' . $url;
$json = file_get_contents('http://www.youtube.com/oembed?url='.urlencode($code));
$video = json_decode($json);
?>
<img src="<?php echo $video->thumbnail_url ?>" />
拉动缩略图时,有些人可能会注意到缩略图顶部和底部的黑色边框。要解决此问题,请使用以下代码:
<a href="<? if($code) {?><?php echo $code; ?><? } ?>">
<div class="yt-thumbnail" style="background:url('<?php echo $video->thumbnail_url ?>') center no-repeat;"></div>
</a>
// in your css file
.yt-thumbnail{
height: 164px;
width: 300px;
background-size: 300px 220px;
}
【问题讨论】: