从wordpress的帖子页面抓取Youtube嵌入代码


Grab Youtube embed code from a post page in wordpress

我需要以某种方式从帖子页面抓取嵌入代码,这样我就可以在存档页面中包含一个小视频版本。基本上不是显示典型的特色图像和摘录,我想包括一个小版本的视频,加上摘录。类似于Youtube搜索结果页面。问题是,我相信视频代码是在get_the_content();

在filters.php

function ar2_add_embed_container( $html ) {
    return '<div class="entry-embed">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'ar2_add_embed_container' );

我如何使用它?任何帮助都会很感激。

谢谢brasolfilo,你的建议指引了我正确的方向。

我假设嵌入是一个自定义的"视频"字段。事实并非如此。对于任何想要为视频存档页面抓取视频的人,你需要首先在你的帖子上创建这个自定义字段

步骤1:p>基本上你是在创建你的自定义字段(我把它命名为video,你可以给它取任何名字)

步骤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

这应该给你一个起点,以集成到你的模板或任何东西。:)