I have a custom field ‘banner’ on every page and post. I want to display loop of posts on a page. On top of this page there should be image ‘banner’, and in the loop of posts I’d like to show the ‘banner’ iamge for each post in thumbnail size.
Sounds easy but whatever I do, the thumbnails are displaying the main page banner instead of their own ‘banner’ images.
I tried:
$banner = get_field(‘banner’, $post->ID);
with no effect
This is loop I tried
<?php
$args = array(
‘posts_per_page’=>15
);
$top_banner = get_field(‘top_banner’);
$top_banner_size = $top_banner[‘sizes’][‘medium’];
$wp_query = new WP_Query($args);
?>
<?php wp_reset_query(); ?>
and in header I display the main banner image on top of the page using the_field.
Why all the images are using the main page image? (they sue the same custom field name)
Hi @fanta00
Please add your code using the code tag so it shows properly. Regarding your issue, I believe you can do something like this:
$wp_query = new WP_Query($args);
?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php $top_post_banner = get_field('top_banner', get_the_ID()); ?>
<img src="<?php echo $top_post_banner['sizes']['medium']; ?>" alt="<?php echo $top_post_banner['alt']; ?>" />
<?php endwhile; ?><!– end of the loop –>
<?php wp_reset_query(); ?>
I hope this helps.