无法更改ACF Gallery图像大小

时间:2017-05-19 14:04:48

标签: php html css wordpress advanced-custom-fields

我不知道如何更改图库中图片的大小。我已经尝试在图像上放置一个类,并使用css来改变大小,这个大小不起作用,因为类被忽略了。我也尝试使用缩略图,大中型和大型更改大小,但图像不会增长超过150像素×150像素。如何更改图像大小并使其响应?

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <?php 

            $image_ids = get_field('gallery', false, false);

            $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';

            echo do_shortcode( $shortcode );

            ?>

            <?php 

            $images = get_field('gallery');

            if( $images ): ?>

                <ul class="row">
                    <?php foreach( $images as $gallery_images ): ?>
                        <li class="col-md-4">
                            <a href="<?php echo $gallery_images['url']; ?>">
                                 <img src="<?php echo $gallery_images['sizes']['medium']; ?>" alt="<?php echo $gallery_images['alt']; ?>" />
                            </a>
                            <p><?php echo $gallery_images['caption']; ?></p>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

您可以尝试将自己的图片尺寸添加到functions.php。这是manuel:WordPress add_image_size() function。您将不得不重新上传图片,因为它不会自动重新生成缩略图。

之后,将class="img-responsive"添加到您的img元素中,引导程序将其用于响应式图像。

答案 1 :(得分:0)

编辑:

根据ACF,你可以试试这个:

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <?php 

            $image_ids = get_field('gallery', false, false);

            $shortcode = '[gallery ids="' . implode(',', $image_ids) . '"]';

            echo do_shortcode( $shortcode );

            ?>

            <?php 

            $images = get_field('gallery');
            $size = 'thumbnail';                            // Here size Defined (thumbnail, medium, large, full or custom size)
            $thumb = $images['sizes'][ $size ];             // Here Initiate the size you want
            $width = $images['sizes'][ $size . '-width' ];  // Here you can get the specific size
            $height = $images['sizes'][ $size . '-height' ];

            if( $images ): ?>

                <ul class="row">
                    <?php foreach( $images as $gallery_images ): ?>
                        <li class="col-md-4">
                            <a href="<?php echo $gallery_images['url']; ?>">
                                 <img src="<?php echo $thumb ; ?>" alt="<?php echo $gallery_images['alt']; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
                            </a>
                            <p><?php echo $gallery_images['caption']; ?></p>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </div>
    </div>
</div>