Support

Account

Home Forums Add-ons Repeater Field Hiding URL linking in repeater

Solved

Hiding URL linking in repeater

  • Inside a repeater “people” I have a text field “person” and a URL field “person_url”.
    While “person” is mandatory, “person_url” is not, how can i make it so that when there is a “person” without a “person_url” the hyperlink deactivates? Heres my code.

    <?php if( have_rows('people') ): ?>
       <?php while( have_rows('people') ): the_row(); 
          // vars
          $person = get_sub_field('person');
          $person_url = get_sub_field('person_url');
       ?>
          <span class="person">
             <a href="<?php echo $person_url; ?>">
                <?php echo $person; ?>
             </a>
          </span>
       <?php endwhile; ?>
    <?php endif; ?>
  • I’d do it something like this.

    
    <?php if( have_rows('people') ): ?>
       <?php while( have_rows('people') ): the_row(); 
          // vars
          $person = get_sub_field('person');
          $person_url = get_sub_field('person_url');
          if ($person_url) {
             $person = '<a href="'.$person_url.'">'.$person.'</a>';
          }
       ?>
          <span class="person">
                <?php echo $person; ?>
          </span>
       <?php endwhile; ?>
    <?php endif; ?>
    
  • It worked like a charm! Thanks a lot!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Hiding URL linking in repeater’ is closed to new replies.