【问题标题】:Bootstrap : adding img-responsive class to thumbnailBootstrap:将 img 响应类添加到缩略图
【发布时间】:2016-02-08 10:10:28
【问题描述】:

我必须将 img-responsive 类添加到 wordpress 页面模板中的图像。 我的文件名为 single-product.php。

这是我的代码

 <div class="col-md-6 col-xs-12" style="margin-top:35px;">
    <h1><?php the_title();?></h1>
  </div>
  <div class="col-md-6 col-xs-12">
   <?php  the_post_thumbnail();?>
 </div>

现在我的问题是如何将类添加到缩略图?

请帮助我。

【问题讨论】:

    标签: php css wordpress twitter-bootstrap


    【解决方案1】:

    您可以在 the_thumbnail 函数中传递类名。

     <?php the_post_thumbnail('thumbnail', array('class' => 'your-class-name')); ?>
    

    更多参考 https://codex.wordpress.org/Function_Reference/the_post_thumbnail

    【讨论】:

    • 我也可以在数组中传递 style='' 吗?
    【解决方案2】:

    the_post_thumbnail() 有两个参数,大小和属性数组。您可以在数组中设置的属性之一是类,因此示例如下所示

    <?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
    

    您可能希望将缩略图更改为您想要的大小,或者您可以将其留空。一如既往地在 codex 中搜索有问题的函数,它通常有答案 https://codex.wordpress.org/Function_Reference/the_post_thumbnail

    【讨论】:

      【解决方案3】:

      这样,

      <?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
      

      此外,在代码中使用内联样式也不是一个好习惯。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-05-20
        • 1970-01-01
        • 1970-01-01
        • 2014-06-30
        • 2020-04-15
        • 1970-01-01
        • 2018-08-12
        相关资源
        最近更新 更多