Support

Account

Home Forums Add-ons Flexible Content Field Output checkbox items in an ordered list

Helping

Output checkbox items in an ordered list

  • Hi – I have a flexible field that contains a “content block” of checkboxes. For some reason I cannot get the checkboxes to display in individual li’s. It outputs the checkbox items one after the other..

    
    <?php
    	// check if the flexible content field has rows of data
    	if( have_rows('flexible_content') ):
    
    	 	// loop through the rows of data
    	    while ( have_rows('flexible_content') ) : the_row();
    if( get_row_layout() == 'social_proof_logos' ):
    		        //$field = get_sub_field_object('social_proof');
    		        $field = the_sub_field('social_proof');
    				$value = $field['value'];
    				$choices = $field['choices'];
    
    				if( $value ) :
    					echo '<ul>';
    			 		foreach( $value as $v ):
    						echo '<li>';
    							echo $choices[ $v ];
    						echo '</li>';
    					endforeach;
    					echo '</ul>';
    				endif;
    			endif;
    endwhile;
    	else :
    	    // no layouts found
    	endif;
    	// End
    ?>
    
  • made a couple minor changes to your code

    
    <?php
      // check if the flexible content field has rows of data
      if( have_rows('flexible_content') ):
      
        // loop through the rows of data
        while ( have_rows('flexible_content') ) : the_row();
          if( get_row_layout() == 'social_proof_logos' ):
            $field = get_sub_field_object('social_proof');
            $choices = $field['choices'];
            $value = the_sub_field('social_proof');
            
            if( $value ) :
              echo '<ul>';
              foreach( $value as $v ):
                echo '<li>';
                echo $choices[ $v ];
                echo '</li>';
                endforeach;
              echo '</ul>';
            endif;
          endif;
        endwhile;
      else :
        // no layouts found
      endif;
      // End
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Output checkbox items in an ordered list’ is closed to new replies.