neilgee
3/13/2015 - 12:34 AM

ACF Repeater layout in Genesis

ACF Repeater layout in Genesis

<?php

add_action( 'genesis_before_loop', 'trs_testimonial_repeater_page' );

function trs_testimonial_repeater_page () {

//My ACF Fields for reference
//testimonials - field group
//testimonial - sub-field
//testimonial_header - sub-field

if( is_page( 'testimonials' ) ) {//target the testimonials page

remove_action( 'genesis_loop', 'genesis_do_loop' );//remove default loop
add_action( 'genesis_loop', 'trs_testimonial_loop' );//add in the repeater loop below

function trs_testimonial_loop () {

// check if the repeater field has rows of data
if( have_rows('testimonials') ):

 	// loop through the rows of data
    while ( have_rows('testimonials') ) : the_row();

        // display a sub field value
		echo 	'<div class="entry-content testimonials">
			 <p>' . get_sub_field('testimonial') . '</p>
			 <h2>' . get_sub_field('testimonial_header') . '</h2>
			 </div>';

    endwhile;

else :

    // no rows found

endif;
		}

	}
}