Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active December 28, 2017 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilgee/977329a5932551133196 to your computer and use it in GitHub Desktop.
Save neilgee/977329a5932551133196 to your computer and use it in GitHub Desktop.
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment