我只想显示“type”的第一个元素,而不是所有具有“payment services”类型的元素。我该怎么做?希望有人能帮我。。。
<?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; ?>