D
D
Daniil Cherny2020-07-15 14:56:24
WordPress
Daniil Cherny, 2020-07-15 14:56:24

Why does it show the same images?

Everything works, except for the thumbnail output. It is displayed as expected, but everywhere the same image.

$args = array(
                              'numberposts' => 12,
                              'category' => 6,
                              'post_status' => 'publish',
                            ); 

                            $result = wp_get_recent_posts($args);

                            foreach( $result as $p ){ 
            ?>
        
                    <div class="row section">
          <div class="col-lg-5 left-image">
     <?php the_post_thumbnail(); ?>
                        </div>
                                  <div class="col-lg-7">
                            <h4><?php echo $p['post_title']; ?></h4>
                            <p><?php echo $p['post_excerpt']; ?></p>
                        </div>
                    </div> 
             <div class="border-top"></div>

                 <?php
              } 
              ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Chefranov, 2020-07-15
@wannacry220

the_post_thumbnail();
change to

if ( has_post_thumbnail( $p["ID"]) ) {
      echo  get_the_post_thumbnail($p["ID"],'thumbnail');
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question