如何获取视频的海报(缩略图)

时间:2013-06-26 作者:Tariq

我正在使用下面的功能获取所有视频,它工作正常。现在我想从视频中获取视频海报图像(缩略图)。如何将视频图像获取为缩略图?我也尝试通过此功能获取缩略图,但它不起作用

    $page_id = 659; 
    $page_data = get_page( $page_id ); 

    if (has_post_thumbnail( $page_data->ID ) ){ ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_data->ID ), \'single-post-thumbnail\' ); ?>
    <img src="<?php echo $image[0]; ?>" width="200" height="212" />
    <?php }?>
我通过此功能获取所有视频

    $args = array
            (
                \'post_type\' => \'attachment\',
                \'post_mime_type\' => \'video\',
                \'order\' => \'DESC\',
                \'orderby\' => \'post_date\',
                \'posts_per_page\'  => -1
            );
            $videoFiles = get_posts($args);
             foreach ($videoFiles as $file) {
    }
我的帖子对象:

WP_Post Object
(
    [ID] => 670
    [post_author] => 1
    [post_date] => 2013-06-26 10:55:51
    [post_date_gmt] => 2013-06-26 10:55:51
    [post_content] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,
    [post_title] => Strike Back
    [post_excerpt] => Composer
    [post_status] => inherit
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => columbia4x3
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2013-06-26 10:55:51
    [post_modified_gmt] => 2013-06-26 10:55:51
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://host.com/wp-content/uploads/2013/06/Columbia4x3.mov
    [menu_order] => 0
    [post_type] => attachment
    [post_mime_type] => video/quicktime
    [comment_count] => 0
    [filter] => raw
)

1 个回复
SO网友:s_ha_dum

您的视频似乎没有“附加”到页面,因此0post_parent. 并且您的查询参数不会将结果限制到任何特定页面。

您将无法使用正常的缩略图功能。您必须使用以下内容wp_get_attachment_image 要获取缩略图,如果您有视频的缩略图。我刚做了个测试did not 为视频生成缩略图。

如果尚未生成缩略图,则这是您的第一个项目。如果您正在生成它们,请解释如何生成。

结束