我尝试植入这个
- Page A0 (images + texts)
-- Page A1
-- Page A1
---Page A2
在页面A1和A2中,我需要从一组字段中检索图库和文本。 如果我使用普通字段而不是组,则可以实现此目的...但是我需要留在组字段中。
<?php
$post_ID = get_the_ID();
$parentpost_id = wp_get_post_parent_id( $post_ID );
$images_images = get_sub_field( "images", $parentpost_id ); //use parents-post field: "broschuren-download"
?>
<div class="hero__image-wrapper <?php if (count ($images_images) > 1) { echo "heroslide" ;} ?> ">
<?php if ( $images_images ) : ?>
<?php foreach ( $images_images as $images_image ): ?>
<img class="hero__image fit-cover" src="<?php echo $images_image['sizes']['large']; ?>" alt="<?php echo $images_image['alt']; ?>" />
<?php endforeach; ?>
<?php endif; ?>
</div>
答案 0 :(得分:0)
get_sub_field()
函数仅在您在父字段上运行的have_rows()
循环内起作用。如果您仍然想使用get_sub_field()
,则必须执行以下操作:
<?php
$post_ID = get_the_ID();
$parentpost_id = wp_get_post_parent_id( $post_ID );
if( have_rows('broschuren-download', $parentpost_id) ): while( have_rows('broschuren-download', $parentpost_id) ): the_row();
$images_images = get_sub_field('images');
if ( $images_images ):
?>
<div class="hero__image-wrapper <?php if (count ($images_images) > 1) { echo 'heroslide'; } ?>">
<?php foreach( $images_images as $images_image ): ?>
<img class="hero__image fit-cover" src="<?php echo $images_image['sizes']['large']; ?>" alt="<?php echo $images_image['alt']; ?>" />
<?php endforeach; ?>
</div>
<?php
endif;
endwhile; endif;
?>