WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Creating a gallery using ACF loop (1 post)

  1. stephaniebane
    Member
    Posted 1 year ago #

    I made a gallery combining ACF and Basic Slider. (http://basic-slider.com/) The admin can control the team members and then they spit out in the gallery. Everything is working fine - except if the loop ends with a grouping of four. I set it up so that if there are four people, it would create a new slide. It works great if there are more people, but if it ends on a four, it creates a blank slide. How can I tell the loop to NOT create a slide if the content doesn't exist? I know it's not an issue with the gallery plugin because I tested it without the ACF capabilities and just static text. The issue is the loop because it creates an extra container. Any ideas? Code below:

    <ul class="bjqs">
    <?php
     $rows = get_field('team_member');
    if($rows)
    {
    $person = 1;
    echo '<li class="slide">';
    foreach($rows as $row)
    {
    echo
    '<div class="ind-team-member">
    <div class="ind-team-member-img-holder"><img src='. $row['image'] . ' alt="'. $row['name'] . '" /></div>
    <div class="ind-team-content"><h4>'. $row['name'] . '</h4>' . $row['contact_information'] .'</div>
    </div>';
    
    if($person==4){ ?>
    </li>
    <li class="slide">
    <?php
    $person = 0;
    }
    $person++;
    }
    }
    ?>
    </li>
    </ul>

    http://wordpress.org/extend/plugins/advanced-custom-fields/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic