0
votes

I am trying to build a Flexible Content which contains 4 possible Layouts (a description, a hero image, a gallery 1col and a gallery 2col). So far I can get the Description and Hero Image subfields to display just fine but the Gallery subfield wont show up on the page. Don't know what I'm doing wrong. Here's the code:

<?php

            while(the_flexible_field("flexible_content")): ?>

                <?php if(get_row_layout() == "description"): // layout: Description ?>

                    <div class="proy-desc">
                        <h2><?php the_sub_field("text"); ?></h2>
                    </div>

                <?php elseif(get_row_layout() == "hero_image"): // layout: Hero Image ?>

                    <div class="proy-img">
                        <?php

                            $image = get_sub_field('image');

                            elseif( !empty($image) ): ?>

                                <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

                        <?php ?>
                    </div>

                <?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>

                    <div class="gallery">
                        <?php $images = get_sub_field('gallery_image_50p');
                           if( $images ): ?>
                              <ul>
                                <?php foreach( $images as $image ): ?>
                                    <li>
                                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                    </li>
                                <?php endforeach; ?>
                              </ul>
                        <?php ?>
                    </div>
                    <?php endif; ?>

                <?php elseif(get_row_layout() == "gallery_100p"): // layout: Gallery 50p ?>

                    <div class="gallery">
                        <?php $images = get_sub_field('gallery_image_100p');
                           if( $images ): ?>
                              <ul>
                                <?php foreach( $images as $image ): ?>
                                    <li>
                                        <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                    </li>
                                <?php endforeach; ?>
                              </ul>
                        <?php ?>
                    </div>
                    <?php endif; ?>

                <?php endif; ?>

            <?php endwhile; ?>
1

1 Answers

0
votes

You did not close your if statement. See below:

<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>

                <div class="gallery">
                    <?php $images = get_sub_field('gallery_image_50p');
                       if( $images ): ?>
                          <ul>
                            <?php foreach( $images as $image ): ?>
                                <li>
                                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                </li>
                            <?php endforeach; ?>
                          </ul>
                    <?php ?>
                </div>
            <?php endif; ?>

Change your section to this:

<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>

                <div class="gallery">
                    <?php $images = get_sub_field('gallery_image_50p');
                       if( $images ): ?>
                          <ul>
                            <?php foreach( $images as $image ): ?>
                                <li>
                                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                </li>
                            <?php endforeach; ?>
                          </ul>
                    <?php endif; ?>
                </div>

Your endif; was in the wrong spot. Everything else looks right, so give this a try.