Last active
August 29, 2015 14:16
-
-
Save FriendlyWP/86cff5341dca045219e3 to your computer and use it in GitHub Desktop.
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.
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
<?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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment