0

I am new to Wordpress templating and php development. I am working on a template to pull in multiple post thumbnails on a single page from multiple posts. The trouble I am having is that the featured images are all the same, inheriting the first post's image. Below is my code - any help on what I need to do to have each posts contain their own featured image would be greatly appreciated :)

 <div class="col-lg-2 text-center">
              <div class="soap-container tire-clean">
                 <?php
                $post_id = 35;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, 'full'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#tireModal"><img width="100%" src="<?php echo get_the_post_thumbnail('35', 'full'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#tireModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>


            <div class="col-lg-2 text-center">
              <div class="soap-container tire-clean">
                 <?php
                $post_id = 37;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, 'full'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#tireModal"><img width="100%" src="<?php echo get_the_post_thumbnail('37', 'full'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#tireModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>
            <div class="col-lg-2 text-center">
              <div class="soap-container mega-foam">
                 <?php
                $post_id = 39;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, 'full'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#foamModal"><img width="100%" src="<?php echo get_the_post_thumbnail('39', 'full'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#foamModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>
1

try using:

        $featured_img_url = get_the_post_thumbnail_url($queried_post->ID, 'full'); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.