Home › Forums › Add-ons › Repeater Field › Repeater Inside of Flexible Content.
Hello, I am trying to create a gallery based on the product being selected from the page. If the product is selected but does not have a gallery created for that product I am trying to make it so it falls back onto a default gallery. I am able to get both to display but not independently based on if the gallery exist. Any help would be great! Thanks
<?php
$category = get_field( 'product_category' );
$product_category = $category['value'];
if($product_category == "doors") {
$product = 'doors';
} else if($product_category == "windows") {
$product = 'windows';
} else if($product_category == "gutters") {
$product = 'gutters';
} else if($product_category == "roofing") {
$product = 'roofing';
} else if($product_category == "siding") {
$product = 'siding';
} else if($product_category == "outdoor") {
$product = 'outdoor';
} else {
$product = 'default';
}
?>
<?php if(get_field('galleries','option')): ?>
<?php while ( have_rows('galleries', 'option') ) : the_row();?>
<?php if (!empty( have_rows(''.$product.'_gallery_options', 'option') )): ?>
<?php while (!empty( have_rows( ''.$product.'_gallery_options', 'option' ))): the_row();
$image = get_sub_field('image', 'option');
$title = get_sub_field('image_title', 'option');
$link = get_sub_field('image_link', 'option');
?>
<div class="product-bg">
<div class="product-image" style="background-image:url(<?php echo $image ; ?>); background-size: cover;"></div>
<div class="product-title">
<h4><?php echo $title ; ?></h4>
</div>
<div class="product-button">
<a class="slider-btn" href="#fix">Get Your Free Estimates</a>
</div>
<a href="<?php echo $link ; ?>" class="learn-more">More info here</a>
</div>
<?php endwhile; ?>
<?php else:?>
<?php while (!empty( have_rows( 'default_gallery_options', 'option' ))): the_row();
$image = get_sub_field('image', 'option');
$title = get_sub_field('image_title', 'option');
$link = get_sub_field('image_link', 'option');
?>
<div class="product-bg">
<div class="product-image" style="background-image:url(<?php echo $image ; ?>); background-size: cover;"></div>
<div class="product-title">
<h4><?php echo $title ; ?></h4>
</div>
<div class="product-button">
<a class="slider-btn" href="#fix">Get Your Free Estimates</a>
</div>
<a href="<?php echo $link ; ?>" class="learn-more">More info here</a>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
The topic ‘Repeater Inside of Flexible Content.’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.