• Hi,

    I would be very grateful to the WP community if someone can help me modify some code I found this forum that enables videos to be displayed on my homepage.

    I have a basic blog style site with recent posts listed on the homepage. The problem I was having is videos would not show up on the homepage because you can’t assign a video as a featured image. I did not want to use thumbnail images for videos. I want users to be able to play videos without clicking through to a post.

    So I found some code on this forum that has done an amazing job of doing just that. If a video is embed in a post it will automatically post the video where the featured image would usually be.

    But now I have ran into 2 problems with the code…

    1) If I have more than 1 video embed it will not show any videos and only show the post title on my homepage.

    2) If I try to add a featured image as a thumbnail of the video for my rent post sidebar widget, the code will show the featured image AND the video below it.

    I need to be able to assign a featured image in the post that will show as post thumbnail only on sidebar if possible. I don’t want the thumbnail to show above the video on the homepage or within the post.

    Then secondly I need the code to allow more than one video in a post and make it select the first video in the post as the video that gets displayed on the homepage.

    Here is the code from my features.php.

    /** Add Video Homepage */
        function catch_video() {
          global $post, $posts;
          $first_vid = '';
          ob_start();
          ob_end_clean();
          $output = preg_match_all('/<iframe.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
          $first_vid = $matches [1] [0];
    
          if ($output == '1') {
          echo '<iframe width="630" height="350" src="';
          echo $first_vid;
          echo '" frameborder="0" allowfullscreen></iframe>';
          }
        }

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    [No bumping, thank you.]

  • The topic ‘Help me modify code for videos in homepage posts’ is closed to new replies.