1
試圖在我的新WordPress的Youtube利基主題做一些事情。我的主題中有一個標籤供用戶輸入Youtube手錶?v = xxxxxxxxxxx ID。當他們輸入xxxxxxxxxxx網址時,會輸出視頻,通過'循環'查詢顯示每個標籤16個帖子。Youtube獲得縮略圖
工作實例here
我已經看過這個谷歌開發者控制檯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 ?>" />
在拉動縮略圖時,您可能會注意到縮略圖頂部和底部的BLACK BORDERS。爲了解決這個問題使用下面的代碼:
<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;
}
這是我誤會......我怎麼搶JSON文件關閉FTP?我想我可以這樣做: 'http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv% <?如果($ url){?><?php echo $ url; ?> } ?>' 但是,我會怎麼去拉縮圖並調用它? – FlannelBeard
請參閱:http://stackoverflow.com/questions/15617512/get-json-object-from-url –
找到[this](http://stackoverflow.com/questions/10377244/how-to-correctly-use - 從YouTube上插入拇指)以及...看着它。 – FlannelBeard