Created
August 19, 2016 15:24
-
-
Save johnkvang/036fde5ae20a3fd88f38617b8c88906a to your computer and use it in GitHub Desktop.
Create a 4-Column list looping through an ACF Repeater Field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This snippet will loop through my ACF Repeater Field and create a large list of websites (or whatever you want). | |
// Then it will create 4 individual lists from that large list of websites. Making it easier for me | |
// to style and/or create a 4-column list. | |
<?php | |
// Name of Repeater field | |
$names_array = get_field( 'field_name' ); | |
// Counts Users | |
$name_count = count( $names_array ); | |
// Number of columns total you want | |
$colcounter = 4; | |
// Determines the number of users per column | |
$names_per_list = $name_count / 4 ; | |
// Rounds decimals up to next number | |
$list_names = ceil( $names_per_list ); | |
//splits Array into 4 smaller arrays | |
$name_chunks = array_chunk( $names_array, $list_names ); | |
?> | |
<?php foreach ( $name_chunks as $name_chunk ) : ?> | |
<div class="column"> | |
<?php foreach ( $name_chunk as $names ) : ?> | |
<?php | |
// I am echoing the 'website' field inside the ACF Repeater | |
echo esc_html( $names['website'] ); | |
?> | |
<?php endforeach; ?> | |
</div> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment