1

I have this bootstrap slider that doesn't seem to be grabbing the video links properly.

This is the code I have:

        <?php $myCarousel = get_order_field('projectdetails_image'); // use the Custom Group name 
        if( !empty( $myCarousel )) {
                foreach($myCarousel as $carousel){
                $myimg = get('projectdetails_image',1,$carousel);
                    if ( !$myimg ) {
                    $videos = get_order_field('video_vimeo');
                    foreach($videos as $video){
                        if ( get('video_vimeo',TRUE) ) {
                                echo "<div class='item active black'><div id='video-wrap'>";
                                echo get('video_vimeo',1,$video);
                                echo "</div></div>";
                        }
                        else {}
                        }   
                    }
                    if ( $myimg ) {
                        echo "<div class='item".( $counter == 0 ? ' active' : '' )."'>";
                        echo '<img src="';
                        echo $myimg;
                        echo '"/>';
                        echo "</div>";
                        $counter++;
                
                        $videos = get_order_field('video_vimeo');
                        foreach($videos as $video){
                            if ( get('video_vimeo',TRUE) ) {
                                echo "<div class='item black'><div id='video-wrap'>";
                                echo get('video_vimeo',1,$video);
                                echo "</div></div>";
                            }
                        }
                    }
                }
            }
            ?>

The bottom if statement is giving me problems:

if ( $myimg ) {
                    echo "<div class='item".( $counter == 0 ? ' active' : '' )."'>";
                    echo '<img src="';
                    echo $myimg;
                    echo '"/>';
                    echo "</div>";
                    $counter++;

                    $videos = get_order_field('video_vimeo');
                    foreach($videos as $video){
                        if ( get('video_vimeo',TRUE) ) {
                            echo "<div class='item black'><div id='video-wrap'>";
                            echo get('video_vimeo',1,$video);
                            echo "</div></div>";
                        }
                    }
                }

For some reason its outputting a <div class='item black'> after every <div class='item'> whereas I would like it to output the <div class='item black'> only after all the <div class='item'>'s have been outputted.

I hope that makes sense. If someone could just point me in the right direction that would be great.

4
  • have you tried moving the for loop? Commented Mar 19, 2013 at 16:22
  • I did. Perhaps Im not moving it to the right place? Commented Mar 19, 2013 at 16:25
  • Haha I moved it out of the other for loop and it worked! Commented Mar 19, 2013 at 16:32
  • No problem. I posted my comment as an answer. Commented Mar 19, 2013 at 16:35

1 Answer 1

1

Move your for loop outside of the outer for loop, which is causing it to be executed on every iteration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.