仅显示acf类型的foreach循环的第一个元素

时间:2018-10-30 11:01:21

标签: foreach advanced-custom-fields

我只想显示“类型”的第一个元素,而不是所有类型为“支付服务”的元素。我怎样才能做到这一点?希望有人能帮助我...

<?php if( have_rows('events', 4127) ):
                    while ( have_rows('events', 4127) ) : the_row();

                        $types = get_sub_field('type');

                        foreach($types as $type) {
                            if ($type == "payment-services") { ?> 



                        <div class="item-<?php foreach($types as $type ): echo $type; echo ' ' ; endforeach; ?>">
                            <img class="events-images" src="<?php the_sub_field('image', 4127); ?>" alt="">
                            <h2 class="events-title"><?php the_sub_field('title', 4127); ?></h2>
                            <p class="events-date"><?php the_sub_field('date', 4127); ?></p>
                            <p class="events-location"><?php the_sub_field('location', 4127); ?></p>
                            <a class="events-url btn" href="<?php the_sub_field('url', 4127); ?>"><?php the_sub_field('url_text'); ?></a>
                        </div>

                         <?php break; ?>
                    <?php }

                         } 
                endwhile;
            endif; ?>

0 个答案:

没有答案