ACF repeater with nested relationship field, used in widget for ACF Widgets plugin integration (http://acfwidgets.com/). Used on http://julialondon.com/about/ in sidebar to display featured books.
<?php
if (have_rows('book_features', $acfw)) {
$features = get_field('book_features', $acfw);
$count = count($features);
echo '<div class="widget-features count-' . $count . ' cf">';
while ( have_rows('book_features', $acfw) ) { the_row();
$headline = get_sub_field('headline', $acfw);
$sub_head = get_sub_field('sub_head', $acfw);
$cta = get_sub_field('cta_text', $acfw);
$feature_link = '';
if ( get_sub_field('feature_link', $acfw) ) {
$feature_link = get_sub_field('feature_link', $acfw);
}
if (get_sub_field('featured_book', $acfw)) {
$books = get_sub_field('featured_book', $acfw); ?>
<?php foreach( $books as $book ) {
$img_attr = array(
'title' => trim( strip_tags( $headline ) ),
);
if ($feature_link == '') {
$feature_link = get_permalink( $book->ID );
}
?>
<div class="widget-block">
<a href="<?php echo $feature_link; ?>"><?php echo get_the_post_thumbnail( $book->ID, 'thumbnail', $img_attr ); ?></a>
<h3 class="widget-block-title"><a href="<?php echo $feature_link; ?>"><?php echo $headline; ?></a></h3>
<?php if ($sub_head) { ?><span class="widget-block-subtitle"><?php echo $sub_head; ?></span><?php } ?>
<a href="<?php echo $feature_link; ?>" class="button red"><?php echo $cta; ?></a>
</div>
<?php } //endforeach; ?>
<?php
} // endif get_sub_field featured_book
} //endwhile have_rows book_features;
echo '</div>';
} //endif