I am using the Advanced Custom Fields plugin in WordPress to display rows of different employees. Basically, a User can input data in the Admin section, and it creates an array that can be used to display the data.
Currently, The array is storing 5 values(subarrays):
array (
0 =>
array (
'profile_pic' => 'http://ocdd.vztechsolutions.com/wp-content/uploads/2017/11/jaime.jpg',
'profile_name' => 'Jaime Daignault',
'profile_job' => 'Executive Director',
'profile_email' => '[email protected]',
),
1 =>
array (
'profile_pic' => 'http://ocdd.vztechsolutions.com/wp-content/uploads/2017/11/beth.jpg',
'profile_name' => 'Beth Kessler',
'profile_job' => 'Family Engagement Coordinator',
'profile_email' => '[email protected]',
),
2 =>
array (
'profile_pic' => 'http://ocdd.vztechsolutions.com/wp-content/uploads/2017/11/carrie.jpg',
'profile_name' => 'Carrie Salehiamin',
'profile_job' => 'Operations Manager',
'profile_email' => '[email protected]',
),
3 =>
array (
'profile_pic' => 'http://ocdd.vztechsolutions.com/wp-content/uploads/2017/11/leslie.jpg',
'profile_name' => 'Leslie Sutton',
'profile_job' => 'Policy Director',
'profile_email' => '[email protected]',
),
4 =>
array (
'profile_pic' => 'http://ocdd.vztechsolutions.com/wp-content/uploads/2017/11/ryley.jpg',
'profile_name' => 'Ryley Newport',
'profile_job' => 'Communications Director',
'profile_email' => '[email protected]',
),
)
I want to be able to create one Bootstrap row with 3 columns, if it has 3 subarrays. Otherwise, I want to create 2 rows, with 3 columns each, if there is more than 3 subarrays. So far this is what I created:
// Store Name of custom field(array) from Admin Section
<?php $repeater = get_field('staff'); ?>
<?php if(count($repeater) <= 3): ?>
<?php while(have_rows('staff')) : the_row(); ?>
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12 staffBlock">
<img src="<?php the_sub_field('profile_pic'); ?>" alt="Profile Pic">
<h4 class="staffTitle"><?php the_sub_field('profile_name'); ?></h4>
<p class="staffSubTitle"><?php the_sub_field('profile_job'); ?></p>
<a class="staffEmail" href="mailto:<?php the_sub_field('profile_email'); ?>"><?php the_sub_field('profile_email'); ?></a>
</div>
</div>
<?php endwhile; ?>
<?php elseif(count($repeater) > 3 && count(repeater) <= 6): ?>
<?php while(have_rows('staff')) : the_row(); ?>
// Display first row and 3 columns
// Display second row and remaining columns
<?php endwhile; ?>
<?php endif; ?>
It works great if the Array has 3 subarrays, but I can't seem to wrap my head around how to create two different rows if it has more subarrays.