Php 如何在WordPress上制作响应性缩略图并应用回退图像?

Php 如何在WordPress上制作响应性缩略图并应用回退图像?,php,wordpress,thumbnails,fallback,Php,Wordpress,Thumbnails,Fallback,我已经有了两个独立的代码,都在工作,但我不知道如何在同一个缩略图中使用它们 如果在帖子中找不到图像,此代码将设置默认的回退图像 <a href="<?php the_permalink(); ?>"> <?php if ( has_post_thumbnail() ) the_post_thumbnail( array(600,600) ); else echo '<img src="' . trailingslashit( get_stylesheet_di

我已经有了两个独立的代码,都在工作,但我不知道如何在同一个缩略图中使用它们

如果在帖子中找不到图像,此代码将设置默认的回退图像

<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() )
the_post_thumbnail( array(600,600) );
else
echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.svg' . '" />';
?>
</a>
有人能帮我吗

[解决方案!!]谢谢你,社会43

        <a href="<?php the_permalink(); ?>">
          <?php if( has_post_thumbnail( $post_id ) ) { ?>
          <img src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
          <?php } else {
          echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.svg' . '" />';
          } ?>
        </a>

试试这个。未经测试

<?php if( has_post_thumbnail( $post_id ) ) { ?>
<img title="" alt="" src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">

<?php } else { 

//fallback img here 

} ?>

“style=”宽度:100%;高度:自动;">
        <a href="<?php the_permalink(); ?>">
          <?php if( has_post_thumbnail( $post_id ) ) { ?>
          <img src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">
          <?php } else {
          echo '<img src="' . trailingslashit( get_stylesheet_directory_uri() ) . 'images/default-thumbnail.svg' . '" />';
          } ?>
        </a>
<?php if( has_post_thumbnail( $post_id ) ) { ?>
<img title="" alt="" src="<?=wp_get_attachment_url( get_post_thumbnail_id() ); ?>" style="width:100%; height:auto;">

<?php } else { 

//fallback img here 

} ?>