The Gallery Loop is section of code used by MediaPress to display a list of Galleries. MediaPress Gallery loop is modeled after the WordPress Post Loop. Any HTML or PHP code within the loop is repeated for each of the gallery.
The purpose of Gallery loop is to allow theme developers easily iterate through the collection of galleries. The Fetched galleries depend on the context of the current loop.
Simple MediaPress Gallery Loop:-
An Simple Gallery Loop will look like following:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php while( mpp_have_galleries() ): mpp_the_gallery(); ?> <div class="<?php mpp_gallery_class();?>" id="mpp-gallery-<?php mpp_gallery_id();?>"> <div class="mpp-item-entry mpp-gallery-entry"> <a href="<?php mpp_gallery_permalink() ;?>" class="mpp-item-thumbnail mpp-gallery-cover"> <img src="<?php mpp_gallery_cover_src( 'thumbnail' ) ;?>" /> </a> </div> <?php do_action( 'mpp_before_gallery_title' ); ?> <a href="<?php mpp_gallery_permalink() ;?>" class="mpp-gallery-title"><?php mpp_gallery_title() ;?></a> </div> <?php endwhile; ?> |
Inside the loop, you can use various template tags to generate the data.
List of Important template tags:-
- mpp_gallery_id() :- Prints current gallery ID
- mpp_gallery_title() :- Prints the current Gallery title
- mpp_gallery_permalink() :- Prints the url of the current gallery
- mpp_gallery_slug():- Print Current gallery slug.
- mpp_gallery_description():- Prints current gallery description.
- mpp_gallery_cover_src( $size ) :- Prints the src of the cover file. $size is one of the registered sizes( thumbnail, mid, full etc )
- mpp_gallery_class( $custom_classes ):- Prints all the css classes that should be applied to the gallery. You can pass the custom classes optionally.
- mpp_gallery_type() :- Print Current Gallery type ( photo, audio,video, doc etc )
- mpp_gallery_status():- Prints current gallery status( private, public, friends, groups etc)
- mpp_gallery_date_created() :- Prints the date this gallery was created
- mpp_gallery_last_updated() :- Prints the date this gallery was last updated. Use time format from general settings.
- mpp_gallery_creator_id():- Prints the Integer Id of the User who created this gallery.
Equivalent Getter functions:-
- mpp_get_gallery_id()
- mpp_get_gallery_title()
- mpp_get_gallery_permalink()
- mpp_get_gallery_slug()
- mpp_get_gallery_description()
- mpp_get_gallery_cover_src()
- mpp_get_gallery_class()
- mpp_get_gallery_type()
- mpp_get_gallery_status()
- mpp_get_gallery_date_created()
- mpp_get_gallery_last_updated()
- mpp_get_gallery_creator_id()
Outside a gallery loop, you can use these functions by passing the gallery id or gallery object as the parameter.
Example:-
Print the title of gallery whose Id is 3.
1 | <?php echo mpp_get_gallery_title( 3 ); ?> |
The options parameter can be:-
- integer:- A valid gallery id or
- MPP_Gallery:- An instance of MPP_Gallery(Documentation for MPP_gallery will be available soon ).