Ich verwende das Advanced Custom Fields Plugin in WordPress, um Zeilen von verschiedenen Mitarbeitern anzuzeigen. Grundsätzlich kann ein Benutzer Daten in den Admin-Bereich eingeben, und es erstellt ein Array, mit dem die Daten angezeigt werden können.PHP - Wie kann ich dynamische Bootstrap-Zeilen und -Spalten in WordPress erstellen, basierend darauf, wie viele Sub-Arrays ein Array hat?
Derzeit Das Array speichert 5 Werte (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]',
),
)
Ich mag eine Bootstrap Reihe erstellen können, mit 3 Spalten, wenn es 3 Subarrays aufweist. Ansonsten möchte ich 2 Zeilen mit jeweils 3 Spalten erstellen, wenn es mehr als 3 Unterfelder gibt. Bisher ist es das, was ich geschaffen:
// 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; ?>
Es funktioniert großartig, wenn das Array 3 Sub-Arrays hat, aber ich kann meinen Kopf nicht scheinen zu umwickeln, wie zu schaffen zwei verschiedene Reihen, wenn es mehr Subarrays hat.