• Hey Guys,

    I’m trying to modify this loop (from page-blog.php), in order to scan for – and display embedded videos (such as YouTube or Vimeo).
    It is searching for images by default and lists their thumbnails.

    Instead of this, I need the loop to check for embedded videos, that then should be directly listed – not just their thumbnail.

    Any ideas? Thanks a lot in advance!

    <?php
    global $wp_query;
    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }	
    
    	$args = array(
    		'post_type' => array('post','image'),
    		'post_status' => 'publish',
    		'orderby' => 'date',
    		'order' => 'DESC',
    		'paged' => $paged
    	);
    	$wp_query = new WP_Query($args);
    
    	while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
    		// IF AN EMBEDDED YOUTUBE OR VIMEO VIDEO HAS BEEN FOUND,
    		// PLACE THE VIDEO (INSTEAD OF A THUMBNAIL) WITHIN THE BLOG-LIST
    		// ELSE...
    
    			<?php echo the_post_thumbnail('blog'); ?>
    
    		// THIS WILL BE THE SAME FOR BOTH CASES (VIDEO OR IMAGE)
    
    		<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
            <p><?php echo get_the_excerpt(); ?></p>
    
    	<?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • Joey

    (@leglesslizard)

    Hey,

    Something like this?

    <?php
    $videos = get_attached_media( 'video', the_ID() );
    if ( ! empty( $videos ) ) {
        foreach ( $videos as $video ) {
            echo wp_get_attachment_url( $video->ID );
        }
    }
    ?>

    It should be self explanatory but it just checks for videos attached to post and echos out their url. Currently it echo’s out all it finds but if that wasn’t required you could just alter the foreach loop.

    Happy coding!

Viewing 1 replies (of 1 total)
  • The topic ‘list videos instead of image-thumbs’ is closed to new replies.