Support

Account

Home Forums Add-ons Repeater Field Removing an element from last row of repeater

Helping

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); ?>&nbsp;|&nbsp;<?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); ?>&nbsp;|&nbsp;<?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>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Removing an element from last row of repeater’ is closed to new replies.