首页 > 解决方案 > 如何修复 wordpress 中的响应式图像错误?

问题描述

我正在尝试在 wordpress 上制作一个响应式主题。当我使用桌面分辨率时,缩略图会 100% 调整为卡,但是当我将分辨率降低到移动设备时,它会比卡更大。为什么会这样?

我已经尝试添加 bootstrap 4 响应式图像类。

<section id="blog" class="blog  d-flex align-items-center mt-5 mb-5">

  <?php query_posts('posts_per_page=3'); ?>


  <div class="container">
<div class="d-flex align-items-center">

 <h1>ÚLTIMAS<BR>PUBLICAÇÕES</h1> </div>    <div class="row">


      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <div class="col-sm-7 col-md-4 mt-3">

        <a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('thumbnail'); ?>" class="rounded-top"></a>
        <div class="card-body border rounded-bottom">

          <h4 class="card-title border-bottom pb-3 "><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h4>
          <p class="card-text"><?php the_subtitle(); ?></p>
          <a href="<?php the_permalink() ?>" class="btn btn-outline-dark btn-sm">Continuar lendo</a>
        </div>

      </div>

      <?php endwhile; ?>

      <?php endif; ?>




    </div>
</section>

预期的:

在此处输入图像描述

现实:

在此处输入图像描述

wordpress 管理面板上配置的缩略图大小为 350 x273px

标签: wordpresstwitter-bootstrapthumbnails

解决方案


请在您的图像中添加“img-responsive”类。正确的代码应该是

<section id="blog" class="blog  d-flex align-items-center mt-5 mb-5">

  <?php query_posts('posts_per_page=3'); ?>


  <div class="container">
<div class="d-flex align-items-center">

 <h1>ÚLTIMAS<BR>PUBLICAÇÕES</h1> </div>    <div class="row">


      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <div class="col-sm-7 col-md-4 mt-3">

        <a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('thumbnail'); ?>" class="rounded-top img-responsive"></a>
        <div class="card-body border rounded-bottom">

          <h4 class="card-title border-bottom pb-3 "><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h4>
          <p class="card-text"><?php the_subtitle(); ?></p>
          <a href="<?php the_permalink() ?>" class="btn btn-outline-dark btn-sm">Continuar lendo</a>
        </div>

      </div>

      <?php endwhile; ?>

      <?php endif; ?>
    </div>
</section>

推荐阅读