douhu2898 2018-10-24 23:06
浏览 89

ACF设置图库缩略图自定义尺寸

THis is php code of ACF Gallery

              <?php 

                $gallery = get_field('slider_1_gallery');

                if( $gallery ): 

                    ?>
                    <div class="big_slider">
                        <?php foreach( $gallery as $index=>$image ): ?>
                            <div class="slide">
                                <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                            </div>
                        <?php endforeach; ?>
                    </div>
                    <div class="miniature_slider">
                        <?php foreach( $gallery as $index=>$image ): ?>
                            <div class="slide">
                                <a href="<?php echo $image['url']; ?>" class="miniature" data-fancybox = "1">
                                    <img src="<?php echo  $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                                    <div class="mask">
                                        <i class="icon_1"></i>
                                    </div>
                                </a>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>

Thumbnails has default sizes. But I need custom sizes for this images

<img src="<?php echo  $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />

How is possible to set width = 165 pixels height = 110 pixels in ACF Gallery ? Is possible do this with scale and crop?

  • 写回答

1条回答 默认 最新

  • dongshuang0011 2018-10-25 06:30
    关注

    If you want to give custom size then add this code to function.php:

    <?php
        add_image_size( 'people-img', 360, 360, true ); 
    ?>
    

    After that you need to fetch like this :

    <?php
            $attachment_id = get_field('bio_image');
            $size = "people-img"; // (thumbnail, medium, large, full or custom size)
            $image = wp_get_attachment_image_src( $attachment_id, $size );
            // url = $image[0];
            // width = $image[1];
            // height = $image[2];
    ?>
    
    <img src="<?php echo $image[0]; ?>" >
    
    评论

报告相同问题?

悬赏问题

  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题