I have a simple question.
My wordpress theme has 2 pages: index.php and single.php. I've used the same code, but I had different results.
single.php
<?php
while(have_posts()) {
the_post();
?>
<h3><?php the_title(); ?></h3>
Posted by <?php the_author(); ?>
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" />
<?php the_content();
}
?>
In the code above, all the content shows up.
index.php
<?php
$args = array(
'posts_per_page' => 3,
);
$blogposts = new WP_Query($args);
while($blogposts->have_posts()) {
$blogposts->the_post();
?>
<div class="col-lg-4">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="Img Post">
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<p class="card-text"><?php the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>" class="btn btn-primary">Leia mais</a>
</div>
</div>
</div>
<?php
}
?>
In this case, all code is working, but the image didn't appeared.
What did I do wrong?