Skip to content

Gallery field type for Custom Metaboxes and Fields for WordPress

Notifications You must be signed in to change notification settings

mattkrupnik/cmb-field-gallery

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMB Field Type: Gallery

Description

Gallery field type for CMB2.

Running an older version of CMB? Check the previous releases.

Installation

You can install this field type as you would a WordPress plugin:

  1. Download the plugin
  2. Place the plugin folder in your /wp-content/plugins/ directory
  3. Activate the plugin in the Plugin dashboard

Alternatively, you can place the plugin folder in with your theme/plugin. After you call CMB:

require_once 'init.php';

Add another line to include the cmb-field-gallery.php file. Something like:

require_once 'cmb-field-gallery/cmb-field-gallery.php';

Usage

pw_gallery - Save a list of attachment IDs. Example:

array(
	'name' => 'Gallery Images',
	'desc' => 'Upload and manage gallery images',
	'button' => 'Manage gallery', // Optionally set button label
	'id'   => $prefix . 'gallery_images',
	'type' => 'pw_gallery',
	'preview_size' => array( 150, 150 ),
	'sanitization_cb' => 'pw_gallery_field_sanitise',
),

Screenshots

Image

Image

To-do

  • Add a clear gallery button

Example front-end output

<?php $gallery_images = get_post_meta( get_the_ID(), '_cmb_gallery_images', true ); ?>
<?php if ( ! empty( $gallery_images ) ) : ?>
	<ul>
		<?php foreach ( $gallery_images as $gallery_image ) : ?>
			<li><?php echo wp_get_attachment_image( $gallery_image, 'thumbnail' ); ?></li>
		<?php endforeach; ?>
	</ul>
<?php endif; ?>

About

Gallery field type for Custom Metaboxes and Fields for WordPress

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 62.6%
  • JavaScript 37.4%