2013-04-17 43 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

这应该给你一个起点融入您的模板或任何食品。 :)