Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Created April 29, 2013 06:28
Show Gist options
  • Save facelordgists/5479997 to your computer and use it in GitHub Desktop.
Save facelordgists/5479997 to your computer and use it in GitHub Desktop.
WORDPRESS: ACF team module
add_shortcode('team_members' , 'display_team_members');
function display_team_members(){
// get_currentuserinfo();
// global $user_level;
// if ($user_level < 10) {
// return false;
// }
ob_start();
echo '<div class="team">';
$columns = 2;
$people = get_field('people');
//echo "<pre>" . print_r($people, true) . "</pre>";
$departments = array();
foreach($people as $dept) {
$departments[$dept['department']][] = $dept;
}
//echo "<pre>" . print_r($departments, true) . "</pre>";
foreach( $departments as $row ) {
echo "<div class='department'>";
echo "<h2>". $row[0]['department'] ."</h2>";
//$people_rows = array_chunk($row, $columns);
$people_rows = array_chunk($row, 2);
foreach( $people_rows as $row ) {
echo '<div class="row">';
foreach( $row as $person ) {
echo '<div class="team-member">';
$photo = wp_get_attachment_image_src( $person['photo']['id'], 'thumbnail' );
//echo '<div class="left-block">';
if( $person['photo'] ):
echo '<img class="left thumbnail" src="' . $photo[0] . '" alt="' . $person['photo']['alt'] . '" width="' . $photo[1] . '" height="' . $photo[2] . '"/>'; endif;
//echo '</div>';
//echo '<div class="right-block">';
if( $person['name'] ): echo '<strong>' . $person['name'] . '</strong>'; endif;
if( $person['title'] ): echo '<br><strong>' . $person['title'] . '</strong>'; endif;
//if( $person['phone'] ): echo '<br><span>' . $person['phone'] . '</span>'; endif;
if( $person['email'] ): echo '<br><span><a class="bottom-spacer" href="mailto:' . $person['email'] . '">' . $person['email'] . '</a></span>'; endif;
if( $person['bio'] ): echo '<br><span class="bio">' . $person['bio'] . '</span>'; endif;
//echo '</div>';
echo "</div>";
}
echo "</div>";
}
echo "</div>";
}
if( $people ):
$i = 0;
$columns = 2;
//echo "count = " .count( has_sub_field('people') );
//$super_array = has_sub_field('people');
while(has_sub_field('people')){
$photo_obj = get_sub_field('photo');
$photo_id = $photo_obj['id'];
$image = wp_get_attachment_image_src( $photo_id, 'thumbnail' );
$name = get_sub_field( 'name' );
$title = get_sub_field( 'title' );
$phone = get_sub_field( 'phone' );
$email = get_sub_field( 'email' );
} // endwhile
endif;
echo '</div>';
$ob_str=ob_get_contents();
ob_end_clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment