【问题标题】:How to wrap thumbnail image inside text in Wordpress?如何在 Wordpress 中将缩略图包装在文本中?
【发布时间】:2016-02-28 01:03:31
【问题描述】:

我知道我必须在 Wordpress 论坛上提问。 但我对stackoverflow 有点疯狂,我先在这里问。 我正在从头开始开发 Wordpress 主题。在我的博客文章中,我想将缩略图包含在文本中。 我使用的代码是

    <div class="row">

        <?php if( has_post_thumbnail() ): ?>
           <div class="col-xs-12 col-sm-4">
            <div class="thumbnail"><?php the_post_thumbnail('small'); ?></div>
           </div>
           <div class="col-xs-12 col-sm-8">
            <?php the_content(); ?>
           </div>

        <?php else: ?>      
            <div class="col-xs-12">
            <?php the_content(); ?>
            </div>

        <?php endif; ?>
   </div>

现在内容和缩略图是并排的。 我喜欢将图像包裹在文本中。 图片是

【问题讨论】:

  • 这是关于 HTML/CSS 而不是 WordPress 本身

标签: css wordpress wordpress-theming


【解决方案1】:

您将缩略图和内容包装在两个不同的列中,这就是它们并排显示的原因。将您的代码更改为:

<div class="row">

        <?php if( has_post_thumbnail() ): ?>
           <div class="col-xs-12 col-sm-12">
            <div class="thumbnail"><?php the_post_thumbnail('small'); ?></div>
            <?php the_content(); ?>
           </div>

        <?php else: ?>      
            <div class="col-xs-12">
            <?php the_content(); ?>
            </div>

        <?php endif; ?>
   </div>

然后用 css 将缩略图 div 向左或向右浮动。

.thumbnail {
 float:left;
}

【讨论】:

  • 太棒了,这就是我想要的。谢谢
猜你喜欢
  • 2015-12-05
  • 2012-03-07
  • 1970-01-01
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-25
相关资源
最近更新 更多