高级自定义字段。图库子字段的灵活内容

时间:2015-10-03 07:54:51

标签: php wordpress advanced-custom-fields

我正在尝试构建一个灵活的内容,其中包含4种可能的布局(描述,英雄形象,画廊1col和画廊2col)。到目前为止,我可以使描述和英雄图像子字段显示得很好但画廊子字段不会显示在页面上。不知道我做错了什么。这是代码:

<?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 个答案:

答案 0 :(得分:0)

您没有关闭if语句。见下文:

<?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_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>

你的结局;是在错误的地方。其他一切看起来都是正确的,所以试一试。