显示(post object)字段类型为ACF的图像



我有一个post对象字段类型的ACF字段组。我有8件产品要展示。我已经显示了标题和永久链接,但无法显示产品图像。任何帮助都会很感激。下面是我的代码:

<div class="col-md-12">
<?php
$featured_posts = get_field('products_images');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $featured_post ): 
$permalink = get_permalink( $featured_post);
$title = get_the_title( $featured_post);
$custom_field = get_field( $featured_post);
?>
<li>
<?php echo get_the_post_thumbnail( $custom_field); ?>
<a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

你应该像这样使用

<div class="col-md-12">
<?php
$featured_posts = get_field('products_images');
if( $featured_posts ): ?>
<ul>
<?php foreach( $featured_posts as $featured_post ): 
$permalink = get_permalink( $featured_post);
$title = get_the_title( $featured_post);
$custom_field = get_field( $featured_post);
?>
<li>
<?php echo get_the_post_thumbnail( $featured_post, 'full' );?>
<a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>

最新更新