Multiple PHP if statements
<section> <?php if ($memberGender == "male") : ?> <?php $val = 'accordion_section_boys';?> <?php endif; ?> <?php if ($memberGender == "female") : ?> <?php $val = 'accordion_section_girls';?> <?php endif; ?> <?php if( have_rows($val) ): ?> <?php while( have_rows($val) ): the_row(); ?> <div class="accordion-section"> BOY SPECIFIC CONTENT </div> <?php endwhile; ?> <?php endif; ?><section>
I would suggest something like:
<?php$genders = array( 'male' => 'accordion_section_boys', 'female' => 'accordion_section_girls',);foreach ( $genders as $gender => $rows_id ) { while( have_rows( $rows_id ) ) { // Here use a template to print the content, by name them like "template-male" and "template-female" include 'template-' . $gender . '.php'; }}?>
If you notice the code, I told you to use a template to show the HTML, so you can call them dynamically and the content will be:
<section> <div class="accordion-section"> CONTENT </div></section>
Because they have the same structure you can do something like this:
<?php if ($memberGender == 'male' || $memberGender == 'female'){ $indicator = ($memberGender == 'male')? 'boys' : 'girls'; if( have_rows('accordion_section_'.$indicator) ){ while( have_rows('accordion_section_'.$indicator) ){ the_row(); } } }?>