2013-04-17 41 views
0

我需要以某種方式抓取帖子頁面中的嵌入代碼,這樣我可以在歸檔頁面中包含一個小視頻版本。基本上,我不想展示典型的精選圖片和摘錄,而是希望包含視頻的小版本以及摘錄。類似於Youtube搜索結果頁面。 問題是,我相信視頻代碼是在get_the_content();Grab Youtube嵌入WordPress的帖子頁面的代碼

這是filters.php

function ar2_add_embed_container($html) { 

    return '<div class="entry-embed">' . $html . '</div>'; 

} 

add_filter('embed_oembed_html', 'ar2_add_embed_container'); 

我如何使用它?任何幫助,將不勝感激。

+0

在[wordpress.se]中搜索'oembed',我很肯定我在那裏看到過相關的代碼。 – brasofilo

回答

0

謝謝brasolfilo,你的建議讓我走向正確的方向。

我認爲嵌入是一個自定義的「視頻」字段。不是這種情況。對於任何人誰願意抓住視頻,你需要首先需要在你的文章中建立這個自定義字段的視頻檔案頁面

第1步:閱讀本 http://codex.wordpress.org/Custom_Fields

基本上你創建自定義字段(我叫我的視頻,你可以命名爲任何)

第2步:在你的循環

while (have_posts()) : the_post(); 

     $id = $post->ID; 

     $video_url = get_post_meta($id, 'video', true); 

     echo wp_oembed_get($video_url, array('width' => 400)); 

    endwhile; 

下面是wp_oembed_get

http://codex.wordpress.org/Function_Reference/wp_oembed_get

這應該給你一個起點融入您的模板或任何食品。 :)