How to retrieve image by ID inside a group?
-
So I have already know to use groups as a loop, but since here I’m not using loops it may be more correct to use the non-loop way.
Which would be this:<?php $hero = get_field('hero'); if( $hero ): ?> <div id="hero"> <img src="<?php echo esc_url( $hero['image']['url'] ); ?>" alt="<?php echo esc_attr( $hero['image']['alt'] ); ?>" /> <div class="content"> <?php echo $hero['caption']; ?> <a href="<?php echo esc_url( $hero['link']['url'] ); ?>"><?php echo esc_html( $hero['link']['title'] ); ?></a> </div> </div> <style type="text/css"> #hero { background-color: <?php echo esc_attr( $hero['color'] ); ?>; } </style> <?php endif; ?>
Taken from the docs here:
https://www.advancedcustomfields.com/resources/group/So the question is how can I specify images by ID inside a group?
Equivalent t this to code:<picture> <?php $imagexoriginal = wp_get_attachment_image_src(2237, 'full'); ?> <?php $imagex815 = wp_get_attachment_image_src(2237, 'medium_large'); ?> <?php $imagex352 = wp_get_attachment_image_src(2237, 'medium'); ?> <source srcset="<?php echo $imagex352[0]; ?>" media="(max-width: 352px)"> <source srcset="<?php echo $imagex815[0]; ?>" media="(max-width: 380px)"> <source srcset="<?php echo $imagexoriginal[0]; ?>" media="(max-width: 767px)"> <source srcset="<?php echo $imagex815[0]; ?>" media="(max-width: 815px)"> <source srcset="<?php echo $imagexoriginal[0]; ?>" media="(min-width: 816px)"> <img class="thumbnail" srcset="<?php echo $image2xretina[0]; ?>" alt="<?php the_title(); ?>"> </picture>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to retrieve image by ID inside a group?’ is closed to new replies.