高级自定义字段wordpress图像大小

高级自定义字段wordpress图像大小,wordpress,advanced-custom-fields,Wordpress,Advanced Custom Fields,我正在创建一个带有旋转木马的网站。要加载图像,我使用Wordpress上的高级自定义字段 这是我的代码: <?php $images = get_field('slides', $post->ID); // clean_print_r($images); if (!empty($images)) : ?> <div class="wide-container"> <div id="slides"> <ul class="sl

我正在创建一个带有旋转木马的网站。要加载图像,我使用Wordpress上的高级自定义字段

这是我的代码:

<?php $images = get_field('slides', $post->ID);
// clean_print_r($images);
if (!empty($images)) :
?>
<div class="wide-container">
    <div id="slides">
        <ul class="slides-container">
        <?php for($i = 0; $i < count($images); $i++): ?>
        <!-- slides -->
            <li>
                <img src="<?php echo $images[$i]['img_slide']['sizes']['large'] ?>" alt="" />
            </li>
        <?php endfor; ?>
        </ul>
    </div>
</div>
<?php endif; ?>

但这不起作用,并且没有加载图像。
在ACF中,我通过ID调用图像附件,它是一个转发器字段。

我不确定如何使用返回ID执行此操作,但如果您返回URL,您将获得完整图像

编辑: 好的,我用图像ID做了一些测试,看起来你把数组处理搞混了。这适用于单个图像:但应该很容易适应您的中继器

$attachment_id = get_field('slide');
$size = "full";


$image = wp_get_attachment_image_src( $attachment_id, $size );
echo '<img src="' . $image[0] . '">';   

//OR

$image = wp_get_attachment_image( $attachment_id, $size );
echo $image[0]; 
$attachment\u id=get\u字段(“幻灯片”);
$size=“full”;
$image=wp\u get\u attachment\u image\u src($attachment\u id,$size);
回声';
//或
$image=wp\u get\u attachment\u image($attachment\u id,$size);
echo$image[0];

我之前的回答是关于return:image ID的,这是线程启动程序指定的,但现在我意识到他实际上是在谈论return:object

/*
*  Return value = Object
*  requires ACF 3.3.7+
*/

$image = get_field('image');

var_dump($image);

/*

Data returned will look like this:

Array
(
    [id] => 540
    [alt] => A Movie
    [title] => Movie Poster: UP
    [caption] => sweet image
    [description] => a man and a baloon
    [url] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
    [sizes] => Array
        (
            [thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-150x150.jpg
            [medium] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-300x119.jpg
            [large] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [post-thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [large-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [small-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-500x199.jpg
        )

)

*/
资料来源:

显然,原始图像不是大小而是URL,因此更改:

['img_slide']['sizes']['large']

你应该没事的

$attachment_id = get_field('slide');
$size = "full";


$image = wp_get_attachment_image_src( $attachment_id, $size );
echo '<img src="' . $image[0] . '">';   

//OR

$image = wp_get_attachment_image( $attachment_id, $size );
echo $image[0]; 
/*
*  Return value = Object
*  requires ACF 3.3.7+
*/

$image = get_field('image');

var_dump($image);

/*

Data returned will look like this:

Array
(
    [id] => 540
    [alt] => A Movie
    [title] => Movie Poster: UP
    [caption] => sweet image
    [description] => a man and a baloon
    [url] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
    [sizes] => Array
        (
            [thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-150x150.jpg
            [medium] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-300x119.jpg
            [large] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [post-thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [large-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg
            [small-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-500x199.jpg
        )

)

*/
['img_slide']['sizes']['large']
['img_slide']['url']