How to pick up images within a post in "the loop" (wordpress)?

Asked

Viewed 38 times

-1

The intention would be to make cards like this from the last posts, inserir a descrição da imagem aqui

Catching the first image of the post this all inside a "the loop". Chunks of the codex I tried, but it didn’t work:

index php.:

?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
?>

content.php (part):

<img src="<?php the_post_thumbnail_url(the_post()); ?>" alt="">

1 answer

0

The function the_post_thumbnail_url has as its first parameter the size that will be the image, you are passing the_post().

So you can omit the size (and then "post-thumbnail" will be used), or specify some other. Also, the method already returns the tag img:

<?php the_post_thumbnail_url(); ?>
  • Does this method return which image within the post? Any with a specific "thumbnail" tag or the first image of the post? I tried to use this function but the image inside the post was not returned.

  • So in fact in the standard Wordpress only has a highlighted image, you are using some plugin? Woocommerce maybe?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.