1. Home
  2. Docs
  3. Post Gallery
  4. Developers
  5. Theme Templates

Theme Templates

You can opt to always display the gallery without having to use the shortcode. You can do this by adding specific function calls inside you theme templates.


the_gallery()

the_gallery() function will print the gallery in the template where ever this piece if code is located.Make sure to place this under the post loop.

Usage example:

<?php the_gallery() ?>

<?php the_gallery( $post_id ) ?>

Parameters

$post_id

(optional) int, default: current post ID.
Sets a post ID, Post Gallery will detect and display the gallery found in the post. If no parameter is set, the function will use the current post ID in the loop.


get_gallery()

get_gallery() function will return an ordered collection of the attachments found in the gallery. Make sure to place this under the post loop.

Usage example:

<?php foreach ( get_gallery() as $attachment ) : ?>
    <img src="<?php echo $attachment->large_url ?>"
        alt="<?php echo $attachment->alt ?>"
    />
<?php endforeach ?>

Parameters

$post_id

(optional) int, default: current post ID.
Sets a post ID, Post Gallery will detect and display the gallery found in the post. If no parameter is set, the function will use the current post ID in the loop.

Returns

Collection (array)
Collection of attachment objects.

Tags , ,
Was this article helpful to you? Yes No