我在我的網站上使用ACF插件。 我想在一個頁面上顯示來自子頁面的中繼器字段的第一行(圖像URL)。獲得ACF中繼器字段的第一行(圖片)
這裏是網頁從我的網站(所有圖像都被加載,但只有第一個顯示的,但我想加載只有第一)
http://www.amsbooking.fr/mattieumoreau/artists/
這裏是我的網頁上的代碼這顯示所有圖像:
<?php
$args = array(
'post_type' => 'page',
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query($args);
if ($parent->have_posts()) : ?>
<?php while ($parent->have_posts()) : $parent->the_post(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<div class="cartouche_menu_artistes">
<div id="parent-<?php the_ID(); ?>" class="parent-page">
<div class="cartouche_crop">
<?php while(has_sub_field('photos_presse')): ?> // my repeater field
<img src="<?php the_sub_field('photo'); ?>" class="artists_menu"> // my sub-field, the one I want to get the first row
<?php endwhile; ?>
</div>
<div class="bandeau"></div>
<h1><?php the_title(); ?></h1>
<div class="bandeau"></div>
</div>
</div>
<?php endwhile; ?>
</a>
<?php endif; wp_reset_query(); ?>
是照片的URL,而不是照片本身...這就是爲什麼我惹上麻煩的第一行,但我想保持這種方式。
我發現這個在網絡上,但我不能管理,以使其適應我的情況:
<?php
$rows = get_field('repeater_field_name'); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row['sub_field_name' ]; // get the sub field value
// Note
// $first_row_image = 123 (image ID)
$image = wp_get_attachment_image_src($first_row_image, 'full');
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" />
這裏是我的代碼的jsfiddle:
可以人幫助我解決這個問題?
非常感謝您的幫助,
感謝您的回覆@Billy馬修斯,但它仍然加載所有的圖片...你可以請檢查源? http://www.amsbooking.fr/mattieumoreau/artists/ – mmdwc
對不起,我不明白你的問題。你只想加載1個帖子? @ user2882154 – Bill
不,我想從所有帖子的中繼器字段中加載第一張圖片。 – mmdwc