php - Wordpress Slick Slider + Magnific Popup

just wondering if I can get the cropped image and also the original of cropped image. Using ACF to build a slider that i

just wondering if I can get the cropped image and also the original of cropped image. Using ACF to build a slider that images are in light box !

 <div class="slide">
    <a href="<?php echo image1_full-sized-image ?>" class="mfp-image">
        <img src="<?php echo image1_cropped-image?>"/>
    </a>
</div>
  • My goal is to cropped images and show them in slider but use the original images in light box !

Thanks,

just wondering if I can get the cropped image and also the original of cropped image. Using ACF to build a slider that images are in light box !

 <div class="slide">
    <a href="<?php echo image1_full-sized-image ?>" class="mfp-image">
        <img src="<?php echo image1_cropped-image?>"/>
    </a>
</div>
  • My goal is to cropped images and show them in slider but use the original images in light box !

Thanks,

Share Improve this question asked Aug 27, 2019 at 11:50 GMedijaGMedija 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, it is possible to get original image and a smaller version of it. Use wp_get_attachment_url($id) to get the full url and wp_get_attachment_image_src($id,$size) for the smaller version.

EDIT: You can get the name of the original uncropped (full) image from the attachments post_meta. Then replace the cropped file name with the original name in the full url. If there's more direct way to do this, I'm all ears.

For example like this,

$image_id = 0; // get this from the saved ACF data
$full_image = wp_get_attachment_url( $image_id );
$thumbnail = wp_get_attachment_image_src( $image_id, 'thumbnail' ); // or some other valid image size

// get original file name and replace cropped name with it
$backup_full = get_post_meta( $image_id, '_wp_attachment_backup_sizes', true );
if ( ! empty( $backup_full['full-orig']['file'] ) ) {
    $full_path = explode( '/', $full_image );
    $full_image = str_replace( end( $full_path ), $backup_full['full-orig']['file'], $full_image );
}

if ( $full_image && is_array( $thumbnail ) ) {
  printf(
    '<div class="slide">
        <a href="%s" class="mfp-image">
            <img src="%s"/>
        </a>
    </div>',
    esc_url( $full_image ),
    esc_url( $thumbnail[0] )
  );
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745208229a4616695.html

相关推荐

  • php - Wordpress Slick Slider + Magnific Popup

    just wondering if I can get the cropped image and also the original of cropped image. Using ACF to build a slider that i

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信