Skip to content

Gallery

JIX edited this page Jul 14, 2020 · 1 revision

Purpose

The Gallery field allows users to select a collection of images.

gallery-field

Once images are added to the field, its UI allows users to:

  • Rearrange and remove existing images directly within the field.
  • Add more images.
  • Sort images by a specific criteria.

Settings

There are no additional settings available for the Gallery field.

Usage

Using a the_value function with the value of a gallery field will use the gallery shortcode of WordPress in order to display the gallery. Using get_value on the other hand will return an array of image IDs if available.

<!-- Display images like a gallery shortcode -->
<?php the_value( 'highlights' ) ?>

<!-- Using images manually -->
<?php
$images = get_field( 'highlights' );

if( $images ) {
	foreach( $images as $image_id ) {
		echo wp_get_attachment_image( $image_id, 'thumbnail' );
	}
}
?>
Clone this wiki locally