?> <article id="archive-<?php the_ID(); ?> " class="post-arch"> <div class="archive-div clearfix" > <?php $first_image = get_first_image(); //get the first image of post if (!empty($first_image)) { echo '<a href="' . $first_image . '">'; echo '<img src="' . $first_image . '">'; echo '</a>'; } else { $video_url = get_first_video(); //get the first video cover of post $class_video = new class_video(); $video_array = call_user_func_array(array($class_video, 'parse'), array($video_url)); $video_img = $video_array['img']['large']; if (empty($video_img)) { echo '<img src="' . get_template_directory_uri() . $video_url . '">'; } else { echo '<a href="' . $video_url . '">'; echo '<img src="' . $video_img . '">'; echo '</a>'; } } ?> <a href="<?php the_permalink();
function the_first_video() { global $post; if (is_object($post) && isset($post->post_content)) { require_once ABSPATH . WPINC . '/class-oembed.php'; $oembed = _wp_oembed_get_object(); $video = get_first_video($post->post_content); if ($video) { echo $oembed->get_html($video, 'maxwidth=220&width=220'); } } }