2014-06-15 4 views
1

새로운 Wordpress Youtube 틈새 테마에서 몇 가지 작업을 시도합니다. 사용자가 Youtube watch를 입력 할 수있는 탭이 있습니까? v = xxxxxxxxxxx id. 그들이 xxxxxxxxxxx url을 입력하면 동영상을 출력하고 '루프'쿼리를 통해 탭 당 16 개의 게시물을 표시합니다.Youtube Get thumbnail

작동 예는 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 ?>" /> 

미리보기 이미지를 가져올 때 일부 사용자는 미리보기 이미지의 위아래에 검은 색 테두리가 나타날 수 있습니다.

<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; 
} 

답변

1

당신은 썸네일, 업 로더의 이름과 제목을 얻을 수에서 oEmbed API를 사용할 수 있습니다 아래의 코드이 사용 문제를 해결합니다.

http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9FOWI6Zftpg 

이것을 JSON 응답을 반환합니다 : 당신이 필요로 예를 들어, 비디오의 URL을 인코딩하는 뷰 카운트가 좀 더 어려운 답변을 볼 수 있습니다 얻기

{ 
    "provider_name":"YouTube", 
    "version":"1.0", 
    "author_url":"http:\/\/www.youtube.com\/user\/NScherzingerVEVO", 
    "type":"video", 
    "author_name":"NScherzingerVEVO", 
    "thumbnail_url":"http:\/\/i1.ytimg.com\/vi\/9FOWI6Zftpg\/hqdefault.jpg", 
    "provider_url":"http:\/\/www.youtube.com\/", 
    "title":"Nicole Scherzinger - Your Love", 
    "height":270, 
    "width":480, 
    "thumbnail_height":360, 
    "html":"\u003ciframe width=\"480\" height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/9FOWI6Zftpg?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", 
    "thumbnail_width":480 
} 

here 자세한 내용은

편집 : 여기

어떻게 PHP에서 축소판 얻는 예입니다 : 이것은 내 오해

<?php 
    $url = 'http://www.youtube.com/watch?v=9FOWI6Zftpg'; 
    $json = file_get_contents('http://www.youtube.com/oembed?url='.urlencode($url)); 
    $video = json_decode($json); 
?> 
<img src="<?php echo $video->thumbnail_url ?>" /> 
+0

가 ... 어떻게이 JSON FTP를 해제 파일을 잡아합니까? 내가 할 수 있다고 가정합니다. 'http://www.youtube.com/oembed?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv% ' 그러나 미리보기 이미지를 가져 와서 호출하면 어떻게 될까요? – FlannelBeard

+0

참조 : http://stackoverflow.com/questions/15617512/get-json-object-from-url –

+0

발견 [this] (http://stackoverflow.com/questions/10377244/how-to-correctly-use) -에서 - 당겨 - 엄지 - 투 - 유튜브)뿐만 아니라 ... 그것을 조사. – FlannelBeard