0

I'm trying to create a YouTube gallery where i use Posts to get info of the iframe and Feature image.

I've built the following gallery:

<?php
global $post;
$args = array( 'posts_per_page' => -1, 'category' => 11 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>


  <!-- YOUTUBE PLAYER -->
         <div class="vid-container">                                                          
         <iframe id="vid_frame" src="<?php echo the_field("embedyoutube"); ?>?rel=0&showinfo=0&autohide=1" controls=0 frameborder="0" width="560" height="315"></iframe>
    </div>

        <!-- PLAYLIST -->
    <div class="vid-list-container">
        <div class="vid-list">
            <div class="vid-item" onClick="document.getElementById('vid_frame').src='<?php the_field("embedyoutube"); ?>?autoplay=1&rel=0&showinfo=0&autohide=1'">
              <div class="thumb"><img src="<?php echo the_field("featureimg"); ?>"></div>
              <div class="desc"><?php the_title(); ?></div>
            </div>
        </div>
    </div>

    <!-- LEFT AND RIGHT ARROWS -->
    <div class="arrows">
        <div class="arrow-left"><i class="fa fa-chevron-left fa-lg"></i></div>
        <div class="arrow-right"><i class="fa fa-chevron-right fa-lg"></i></div>
    </div>

All this code is supposed to show this: this is the gallery but instead it repeats the video player and the carousel bellow over and over.

Like this: http://prntscr.com/ne43dz

I know i'm messing up something with the post loop and the way i'm calling the posts on the slider. I don't know how to improve it further ...

Anybody got any idea?

  • You should definitely switch to WP_Query instead of get_posts(). You also appear to be looping through the markup for the entire gallery for each post. That seems wrong, too. – MikeNGarrett Apr 22 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.