WordPress.org

Forums

Video post format, extra content breaks video embed (1 post)

  1. desmondo
    Member
    Posted 2 years ago #

    I am using the content-video.php include to show the latest video post on my homepage. The include only shows the video from the post and not the rest of the content, which works well.

    My problem is, if I add any content (eg - text, another link, etc) after the link to the video in the post, it breaks my video embed on the homepage. The video and text before and after display fine in the actual post.

    Here is the code I have for content-video.php

    <?php if(strlen( get_the_title() ) >0 ): ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php endif; ?>
    <?php
        $parsedUrl  = parse_url(get_the_content());
        $embed      = $parsedUrl['query'];
        parse_str($embed, $out);
        $embedUrl   = $out['v'];
    ?>
    <iframe width="385" height="217" src="http://www.youtube.com/embed/<?php echo $embedUrl; ?>" frameborder="0" allowfullscreen></iframe>

    And, here is the loop code where I'm including it on the homepage:

    <?php
            $args = array(
                'post_type' => 'post', // if the post type is post
                'posts_per_page' => 1,
                'tax_query' => array(
                array(
                    'taxonomy' => 'post_format',
                    'field' => 'slug',
                    'terms' => 'post-format-video'
                ))
            );
            $my_query = new WP_Query( $args );
            ?>
            <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <div id="latestVideo">
                <?php get_template_part( 'content', 'video' ); ?>
                <a class="more-videos" href="/type/video/">more videos</a>
            </div>
        <?php endwhile; ?>

    Can anyone spot what I'm doing wrong, or do I need to embed the video in a different way?!

    Thanks for any help.

Topic Closed

This topic has been closed to new replies.

About this Topic