Php 在没有插件的情况下,如何在内容字段转发器中使用自定义字段图像裁剪大小?

Php 在没有插件的情况下,如何在内容字段转发器中使用自定义字段图像裁剪大小?,php,html,wordpress,Php,Html,Wordpress,我实现了灵活的内容字段,其中一个布局包括图像。我需要裁剪它的尺寸 我在functions.php中添加了自定义大小: 我的HTML代码,其中要调用自定义裁剪大小: if( have_rows('top_informations') ): while ( have_rows('top_informations') ) : the_row(); ?> <img src="<?php the_sub_field('image')?>">

我实现了灵活的内容字段,其中一个布局包括图像。我需要裁剪它的尺寸

我在functions.php中添加了自定义大小:

我的HTML代码,其中要调用自定义裁剪大小:

if( have_rows('top_informations') ):

    while ( have_rows('top_informations') ) : the_row(); ?>

       <img src="<?php the_sub_field('image')?>">


                                <h2><?php the_sub_field('title_text')?> </h2>


                           <?php endwhile;

                           // echo '</ul>';

                        endif;`

带的行表示子字段图像。我的自定义字段图像设置为返回URL。

首先将图像字段“返回值”设置为“图像ID”,并使用以下代码

<?php $thumb_img=wp_get_attachment_image_src(get_sub_field('image'),'custom-crop'); ?>
<img src="<?php echo $thumb_img[0]; ?>">

然后,您需要使用我评论中的插件重新生成缩略图。

欢迎使用SO!请校对并正确格式化您的帖子。谢谢这似乎很奇怪,但代码返回了我的完整尺寸:不知道为什么。。我的自定义裁剪是否正确添加到functions.php中??似乎无法识别自定义裁剪…如果在添加“添加图像大小”功能之前上载了图像,则需要重新生成缩略图。为此,请使用插件或任何等效工具。
<?php $thumb_img=wp_get_attachment_image_src(get_sub_field('image'),'custom-crop'); ?>
<img src="<?php echo $thumb_img[0]; ?>">
if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails', array('post') ); //add all custom post types which need featured image
    add_image_size( 'custom-crop', 220, 180, true );
}