Last active
December 28, 2017 21:50
-
-
Save neilgee/977329a5932551133196 to your computer and use it in GitHub Desktop.
ACF Repeater layout in Genesis
This file contains 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
<?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