如何将 wordpress 特色图像的大小调整为 620 宽度,调整循环中的任何相应高度,但不是永久调整?

发布于 2024-11-05 15:52:54 字数 319 浏览 0 评论 0原文

这是我正在尝试执行此操作的网站: http://increaseinwebtraffic.com/marywood/deals/

顶部的几笔交易宽度大于 620,但底部的交易宽度较小。我尝试使用下面的代码但没有成功。我用谷歌搜索了一下,只找到了永久的解决方案。

<?php the_post_thumbnail( array(620,295) ); ?>

任何帮助表示赞赏。

Here is the website I am attempting this on: http://increaseinwebtraffic.com/marywood/deals/

The top few deals are larger than 620 width, but the bottom ones are smaller. I tried to use the code below with no success. I've Googled around and only found permanent solutions.

<?php the_post_thumbnail( array(620,295) ); ?>

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┼── 2024-11-12 15:52:54

请尝试以下代码。

<?php
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
if (!empty($thumbnail_id))
{
  $thumbnail = wp_get_attachment_image_src($thumbnail_id, 'full');
  if (count ($thumbnail) >= 3)
  {
    $thumbnail_url = $thumbnail[0];
    $thumbnail_width = $thumbnail[1];
    $thumbnail_height = $thumbnail[2];

    $thumbnail_w = 620;
    $thumbnail_h = floor($thumbnail_height * $thumbnail_w / $thumbnail_width);
  }
}

if (!empty ($thumbnail_url)): ?>
  <img class="thumbnail" src="<?php echo $thumbnail_url; ?>" alt="<?php the_title_attribute(); ?>"
       width="<?php echo $thumbnail_w; ?>" height="<?php echo $thumbnail_h; ?>" />
<?php endif; ?>

http://www.boxoft。净/2011/10/显示-the-wordpress-featured-image-without-stretching-it/

Please try the following code.

<?php
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
if (!empty($thumbnail_id))
{
  $thumbnail = wp_get_attachment_image_src($thumbnail_id, 'full');
  if (count ($thumbnail) >= 3)
  {
    $thumbnail_url = $thumbnail[0];
    $thumbnail_width = $thumbnail[1];
    $thumbnail_height = $thumbnail[2];

    $thumbnail_w = 620;
    $thumbnail_h = floor($thumbnail_height * $thumbnail_w / $thumbnail_width);
  }
}

if (!empty ($thumbnail_url)): ?>
  <img class="thumbnail" src="<?php echo $thumbnail_url; ?>" alt="<?php the_title_attribute(); ?>"
       width="<?php echo $thumbnail_w; ?>" height="<?php echo $thumbnail_h; ?>" />
<?php endif; ?>

http://www.boxoft.net/2011/10/display-the-wordpress-featured-image-without-stretching-it/

波浪屿的海角声 2024-11-12 15:52:54

围绕上面的代码进行设置,然后使用 CSS 设置宽度和高度怎么样?像这样的东西:

CSS

.deals img {
 width: 620px;
 max-height: 295px;
}

HTML / PHP

<div class="deals"><?php the_post_thumbnail( array(620,295) ); ?></div>

What about putting a around that an setting the above code and then using CSS to set the width and height? Something like this:

CSS

.deals img {
 width: 620px;
 max-height: 295px;
}

HTML / PHP

<div class="deals"><?php the_post_thumbnail( array(620,295) ); ?></div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文