Home › Forums › Add-ons › Repeater Field › Removing an element from last row of repeater
Hi! Right now I have a working custom repeater that displays a grey bar in between rows. The issue is that I’d like to stop the grey bar from displaying after the last row in the repeater.
How do I do that?
The code is below. It’s the p class=”devborder” that I’d like to display between all rows but not after the final row. Thanks for any help!
<span class="items">
<?php if( have_rows('repeater_indevelopment', 14) ): ?>
<?php while( have_rows('repeater_indevelopment', 14) ): the_row();
// vars
$project = get_sub_field('project', 14);
?>
<?php if ($project): ?>
<p class="projectname"><?php the_sub_field ('project', 14); ?> | <?php the_sub_field('medium', 14); ?></p>
<p class="projectstage"><?php the_sub_field ('status', 14); ?></p>
<p class="devborder"></p>
<br>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<p class="project name" ><?php the_field('nocontent', 14) ?></p>
</span>
While you could just not display that <p>
element you could put that in a div and then set a border on the div, for example:
HTML
<div class="project-section">
<!-- your content here -->
</div>
CSS
.items .project-section {
border-top: 10px #000 solid;
}
.items .project-section:first-child {
border-top: none;
}
or you can alter the loop the way you suggest by doing something like this:
<span class="items">
<?php if( have_rows('repeater_indevelopment', 14) ): ?>
<?php
$rows = count(get_field('repeater_indevelopment'));
$count = 0;
?>
<?php while( have_rows('repeater_indevelopment', 14) ): the_row();
// vars
$project = get_sub_field('project', 14);
?>
<?php if ($project): ?>
<p class="projectname"><?php the_sub_field ('project', 14); ?> | <?php the_sub_field('medium', 14); ?></p>
<p class="projectstage"><?php the_sub_field ('status', 14); ?></p>
<?php
$count++;
if ($count < $rows) {
?><p class="devborder"></p><?php
}
?>
<br>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<p class="project name" ><?php the_field('nocontent', 14) ?></p>
</span>
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.