Creating an element once inside of a php while loop -



Creating an element once inside of a php while loop -

i trying set slideshow within of wordpress loop. so, want have 1 section of slide content, , 1 section navigation.

here code:

<div id="upcoming_shows"> <?php if ( $shows->have_posts() ) : ?> <?php /* start loop */ ?> <?php while ( $shows->have_posts() ) : $shows->the_post(); ?> <?php //get rid of auto drafts , trash posts $p_status = get_post_status( $post ); if ($p_status != 'trash' , $p_status != 'auto-draft') : ?> <!--i want containing div here created once--> <div id="slides"> <div class="slide" id="slide-<?php echo $post->id; ?>"> <?php the_post_thumbnail(); ?> <p class="show_date"><?php echo get_field('show_date'); ?></p> <h1 class="band_names"><a href="<?php the_permalink(); ?>" alt="link blog post page"><?php the_title(); ?></a></h1> </div><!--end slide--> <!--and end here--> </div><!-- end slides containing div--> <!--then div here containing slides_nav--> <div id="slides_nav"> <!--create 1 time wrapper--> <p class="band_names"><a href=#slide-"<?php $post->id; ?>"><?php the_title(); ?></a></p> </div><!--end slides nav container--> <?php endif; ?><!--end auto draft check--> <?php endwhile; ?> <?php endif; ?><!--end if haveposts--> </div><!--end upcoming_shows-->

what wrap elements class of "slide" in div called "slides", , create set of elements wrapped in div called "slides_nav".

i can't figure out way :

"if first iteration of loop, create div called "slides" around "slide" elements.

"if first iteration of loop, create div called "slide_nav" wrap slide navigation elements" (which created within loop (they title of $shows post , page-internal link slide id matching slide_nav href.)

i tried:

<?php $i=0; if ($i == 0) { echo '<div id="slides">'; $i++; };

and correctly created div, did each slide ( added conditional close div).

i beginner php fyi.

i looked @ answers create 1 time within of loop, , tried few, believe lack of programming knowledge may have me missing simple solution.

thanks

why don't create before loop?

<?php echo '<div class="slides">'; while( // loop ){ // instructions }

php loops conditional

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -