A
A
Anatoly2018-06-05 17:22:41
WordPress
Anatoly, 2018-06-05 17:22:41

How to write php code (in wordpress | post-thumbnails) to make it work?

Help, please, to solve the problem:
You need to get something like this: In functions.php connected: add_theme_support( 'post-thumbnails' ); Below I give the same lines of output, but something is not right in them.<img src='mysite.ru/ava.png' alt='текст'>

<?php
  $args = array(
    'numberposts'     => '0', 
    'category_name'   => 'comments', 
    'order'           => 'ASC', 
    'post_type'       => 'post',
    'suppress_filters' => true,
  );
  $posts = get_posts( $args );
  foreach($posts as $post){setup_postdata($post);   ?>

  <?php echo "<img class='media-object' src='" . get_the_post_thumbnail_url() ."' alt='" . the_field( 'comment_client' ) . "'>";?>

  <img class="media-object" src="<?php get_the_post_thumbnail_url();?>" alt="<?php the_field( 'comment_client' ); ?>">

<?
  }
  wp_reset_postdata();
?>

In html I get the following:
<img class='media-object' src='https://mysite.ru/wp-content/uploads/2018/06/ava.png' alt=''>
<img class="media-object" src="" alt="Иванов Иван, Москва">

Those. In one case, one did not work, in the other, the other.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2018-06-05
@Tolly

Replaced get_the_post_thumbnail_url() with the_post_thumbnail_url() and it seems to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question