Home › Forums › Add-ons › Repeater Field › Wrap entire Repeater Field in a wrapper
This might be covered already, but I cannot find it… how can I wrap my entire repeater field in either an Id or a div? Hoping to use this wrapper to add grid properties 🙂
I keep trying but obviously it just is wrapping each ‘repeated section’ in divs… not what I was hoping for. Must be some sort of If Statement or css (nth child…??) that I’m missing.
Here is my code, where I’m trying to add the id of ‘multiple’ around the complete Repeater:
<div id="multiple">
<?php //begin some repeating fields for if multiple trips to same country */
elseif (get_row_layout() == 'trip_card') : ?>
<?php if (have_rows('multiple_trips')) : ?>
<?php while (have_rows('multiple_trips')) : the_row();
?>
<p><strong><?php the_sub_field('first_trip_title'); ?>:</strong>
<?php the_sub_field('first_trip_date'); ?></p>
</div> <!-- end multiple -->
Thank you ahead of time 🙂
Amy
SORRY this code looks better ~ same as above but w/ variables for easier reading; but still not what I’m looking for, AND I should have mentioned (not that this matters but this Repeater field is inside of a Layout)
This might be easier to read:
<?php //begin some repeating fields for if multiple trips to same country */
elseif (get_row_layout() == 'trip_card') : ?>
<?php if (have_rows('multiple_trips')) :
// loop through the rows of data
while (have_rows('multiple_trips')) : the_row();
//vars
$first_trip_title = get_sub_field('first_trip_title');
$first_trip_date = get_sub_field('first_trip_date');
//display a sub field value
?>
<div id="multiple">
<p><strong><?php echo $first_trip_title; ?>:</strong>
<?php echo $first_trip_date; ?></p>
</div><!-- end of multiple -->
I solved this but maybe this might help someone! I was making it WAY harder then it was!
Here is what I did to get a class called ‘multiple’ or wrapper around my repeater:
<?php //begin some repeating fields for if multiple trips to same country */
elseif (get_row_layout() == 'trip_card') : ?>
<?php if (have_rows('multiple_trips')) :
echo '<div class="multiple">'; //begin wrapper
// loop through the rows of data
while (have_rows('multiple_trips')) : the_row(); ?>
<?php
//vars
$first_trip_title = get_sub_field('first_trip_title');
$first_trip_date = get_sub_field('first_trip_date');
//$counter = 2;
//display a sub field value
?>
<div><strong><?php echo $first_trip_title; ?>:</strong>
<?php echo $first_trip_date; ?></div>
<?php endwhile;
echo '</div>' ?>
<!-- end of wrapper: multiple -->
<?php else : ?>
<?php // no rows found
?>
<?php endif; ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.