Wordpress wp_get_attachment_image_src Size attribute


Wordpress wp_get_attachment_image_src Size attribute

>我正在调用一个函数来显示帖子特色图像并将其发布为背景图像。尺寸是在div 中设置的,但我的客户更新了巨大的原件,想知道是否有办法设置图像的大小以缩小它们:

<?php
    $catquery = new WP_Query( 'cat=23&posts_per_page=1' );
    while($catquery->have_posts()) : $catquery->the_post();
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'featured' );?>
<div onclick="window.location='<?php the_permalink(); ?>'" title="<?php the_title(); ?>">
    <div class="front-page-featured-post"  style="background: url(<?php echo $src[0]; ?> ); background-size: cover; background-repeat:no-repeat;">

在我的函数中:

add_theme_support( 'post-thumbnails' );
  add_image_size('featured', 370, 240, true);

你试过这个吗?

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 370, 340 );
您需要在

实现新的缩略图大小后重新生成图像,只需使用此插件:https://wordpress.org/plugins/regenerate-thumbnails/重新生成所有图像,它将创建尺寸为 370x240 的新图像