【问题标题】:Grab Youtube embed code from a post page in wordpress从 wordpress 的帖子页面中获取 Youtube 嵌入代码
【发布时间】:2013-04-17 00:22:50
【问题描述】:

我需要以某种方式从帖子页面中获取嵌入代码,以便在存档页面中包含一个小型视频版本。基本上,我不想显示典型的特色图像和摘录,而是想包含一个小版本的视频,加上摘录。类似于 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' );

如何使用它?任何帮助,将不胜感激。

【问题讨论】:

标签: php wordpress youtube


【解决方案1】:

感谢 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

这应该为您提供一个集成到您的模板或其他内容中的起点。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多