Home › Forums › Add-ons › Repeater Field › Need to show two Sub Fields on each div
Hey! This is what I need:
<div class="row">
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
</div>
but it is showing all Sub Fields instead of two:
<div class="row">
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
</div>
So far this is what I have:
<?php if (have_rows('testimonials-int')) { $count = 0; ?>
<div class="row">
<?php while(have_rows('testimonials-int')) {
the_row();
$image = get_sub_field('avatar-int');
$content = get_sub_field('content-int');
$name = get_sub_field('name-int');
if ($count % 2 == 0) {
?>
<?php } ?>
<div class="medium-6 columns wrapper">
<img src="<?php echo $image; ?>" alt="Testimonials" />
<?php echo $content; ?>
<span><?php echo $name; ?></span>
</div>
<?php $count++; } ?>
</div>
<?php } ?>
Thanks in advanced!
<?php
if (have_rows('testimonials-int')) {
$count = 0;
?>
<div class="row">
<?php
while(have_rows('testimonials-int')) {
$count++;
if ($count > 2) {
break;
}
the_row();
$image = get_sub_field('avatar-int');
$content = get_sub_field('content-int');
$name = get_sub_field('name-int');
?>
<div class="medium-6 columns wrapper">
<img src="<?php echo $image; ?>" alt="Testimonials" />
<?php echo $content; ?>
<span><?php echo $name; ?></span>
</div>
<?php
}
?>
</div>
<?php
}
?>
Misread your post, I thought you only wanted to show 2, not in each div. The question I have is, what if there’s more than 4?
Not a problem! In fact, I want to show all of them but in this way:
<div class="row">
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
</div>
<div class="row">
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
</div>
<div class="row">
<div class="medium-6 columns">
...
</div>
<div class="medium-6 columns">
...
</div>
</div>
etc.....
I’m using the Zurb Foundation framework. Throwing all of them in just one <div class="row">
is not a good practice because if a div
is higher than the other can break the layout. Thanks and sorry for the misunderstanding, didn’t explain in detail.
<?php
if (have_rows('testimonials-int')) {
$count = 0;
?>
<!-- open the first row -->
<div class="row">
<?php
while(have_rows('testimonials-int')) {
the_row();
if ($count > 0 && ($count % 2 == 0)) {
// close row and open new row
?>
</div>
<div class="row">
<?php
}
$image = get_sub_field('avatar-int');
$content = get_sub_field('content-int');
$name = get_sub_field('name-int');
?>
<div class="medium-6 columns">
<img src="<?php echo $image; ?>" alt="Testimonials" />
<?php echo $content; ?>
<span><?php echo $name; ?></span>
</div>
<?php
$count++;
}
?>
</div><!-- close the last row -->
<?php
}
The topic ‘Need to show two Sub Fields on each div’ is closed to new replies.
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.