Wordpress plugins
Featured Galleries

Featured Galleries

Version : 1.7.1
Tested up to : 4.7.6
Number of download : 14094
Author : Andy Mercer
Average rating : 5 / 5 on 15 votes 15 votes, 5 avg.rating

Screenshots

Featured Galleries
Featured Galleries
Featured Galleries
Featured Galleries

Hello Theme Developers! Have you ever added a Featured Image to a post and thought to yourself, ‘I wish I could add more than one image this way’? Well, now you can. “Featured Galleries” mirrors the Featured Images functionality of WordPress. The only difference is that posts get an entire gallery rather than just a single image. These galleries behave almost exactly like Featured Images, and make use of WordPress’s built in Media Manager. Users can select images, define the order, and save the gallery, all through a simple drag-n-drop interface. Note: This is not a plugin which will add galleries to your website. This is for theme developers. It handles the backend interface for creating featured galleries, and storing them. You will still need to build a gallery on your page templates. –Instructions– Just like with Featured Images themes will need to call a Featured Gallery in any template file where the Featured Gallery should appear. I’ve tried to make this as intuitive as possible. Just like WordPress comes with get_post_thumbnail_id() built-in, you can use get_post_gallery_ids() to call the Featured Gallery. It needs the post’s ID, and will return a PHP array with the ID’s of all images in the post’s Featured Gallery. Additionally you can send a second argument, “string”, which will cause the function to return a comma-delimited string instead of an array. –Examples– This example pulls the entire Featured Gallery, as an array, then loops through to display each as an img. $galleryArray = get_post_gallery_ids($post->ID); <?php foreach ($galleryArray as $id) { ?> <img src="<?php echo wp_get_attachment_url( $id ); ?>"> <?php } ?> You can additionally request a comma-delimited string, instead of an array. $galleryString = get_post_gallery_ids($post->ID,"string"); echo $galleryString; Finally, you may want to just grab the first image of the gallery. You can do this by specifying the number of images to return. The default is -1, which returns all. Setting this to 1 instead, as shown below, will get you only one image. $galleryArray = get_post_gallery_ids($post->ID,1); //If $post->ID is throwing an undefined error, use get_the_ID() instead. (Sometimes the post object isn't defined.) <?php foreach ($galleryArray as $id) { ?> <img src="<?php echo wp_get_attachment_url( $id ); ?>"> <?php } ?> Adding Featured Galleries to a Custom Post Type I’ve included a hook to allow you to easily integrate featured galleries into a custom post type. In your theme functions.php file, simply add this: function add_featured_galleries_to_ctp( $post_types ) { array_push($post_types, 'custom_post_type'); // ($post_types comes in as array('post','page'). If you don't want FGs on those, you can just return a custom array instead of adding to it. ) return $post_types; } add_filter('fg_post_types', 'add_featured_galleries_to_ctp' ); Show the Sidebar In Media Manager By default, the sidebar is hidden in the media manager/uploader popup. However, if you’d like it to be shown, there is an easy filter that you can add to your functions.php file. Example: function show_fg_sidebar( $show_sidebar ) { return true; // ($show_sidebar comes in a false) } add_filter( 'fg_show_sidebar', 'show_fg_sidebar' ); Want to Help? I’d love some help with internationalization. I’m not sure how to do that. Also, if anyone wants to take a look at admin.js, which calls up the media manager, I feel like the way that I open it to the gallery-edit state could be improved. (Opens to featured-gallery state, plugs in pre-selected images, then changes state to gallery-edit, and plugs in pre-selected images. Couldn’t get selection to transfer, so there’s a weird flash as it propagates.)

Download now