Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelderic committed Aug 2, 2018
1 parent 81b2a78 commit 9bbc52b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/assets/scripts/fg-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
self.flags.showDetailsSidebar = false;
}

if ( fgInfoFromPHP.useLegacySelection === '1' && fgInfoFromPHP.useLegacySelection === true ) {
if ( fgInfoFromPHP.useLegacySelection === '1' || fgInfoFromPHP.useLegacySelection === true ) {
self.flags.useLegacySelection = true;
} else {
self.flags.useLegacySelection = false;
Expand Down
105 changes: 11 additions & 94 deletions src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,17 @@ Do you like giving posts a Featured Image? Try out a Featured Gallery. It's like

= 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.
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.
**Note**: This plugin DOES NOT HANDLE THE FRONTEND HTML CREATION. That is left for themes to handle, to allow for maximum flexibility. Featured Galleries just handles the backend/admin interface for creating featured galleries and storing them as metadata. You will need to integrate this into your theme, or use a theme with prebuilt integration.

= --Instructions to Integrate Into Themes-- =
= Instructions to Integrate Into Themes =

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.
I've tried to make this as intuitive as possible Themes can integrate Featured Galleries in the same way they integrate Featured Images. Inside any template file where the gallery should appear, the theme will call the [`get_post_gallery_ids()`](https://github.com/Kelderic/featured-galleries/wiki/get_post_gallery_ids) function. As long as it is used inside the loop, the function doesn't need any parameters. By default, it will return an array of image IDs.

Just like WordPress comes with `get_post_thumbnail_id()` built-in, you can use `get_post_gallery_ids()` to call the Featured Gallery. As long as it is used inside the loop, it doesn't need to be passed any parameters. In that case, by default, it will return a PHP array with the ID's of all images in the post's Featured Gallery. However, you can also customize the returned value to suit your needs, with up to three parameters.
= Example =

get_post_gallery_ids( $postID, $maxImages, $returnType );

**Parameters:**

* $postID:
* Type: Integer
* Description: The ID of the post/page that you are loading.
* Default Value: null (which becomes the post ID of the current Post, if the function is called from inside the Loop)
* Possible Values: Any valid post ID, or null.

* $maxImages:
* Type: Integer
* Description: The max number of images to return. If set to -1, all images will be returned.
* Default Value: -1
* Possible Values: Any integer from -1 up through infinity.

* $returnType:
* Type: String
* Description: The format of the returned image IDs.
* Default Value: 'array'
* Valid Values: 'array', 'string'
* 'array' will cause the function to return the image IDs as a PHP array.
* 'string' will cause the function to return the image IDs as a comma delimited string.


= --Examples-- =

**Example 1:** Set inside the Loop. This returns all images in the Featured Gallery, as an array, then loops through to display each using an HTML `<img>` tag.
Set inside the Loop. This returns all images in the Featured Gallery, as an array, then loops through to display each using an HTML `<img>` tag.

$galleryArray = get_post_gallery_ids();

Expand All @@ -62,71 +35,15 @@ Just like WordPress comes with `get_post_thumbnail_id()` built-in, you can use `

}

**Example 2:** Set inside the Loop. This behaves exactly the same as Example 1, it just has all parameters specifically set to their defaults, to demonstrate what is happening.

$galleryArray = get_post_gallery_ids( null, -1, 'array' );

foreach ( $galleryArray as $id ) {

echo '<img src="' . wp_get_attachment_url( $id ) .'">';

}

**Example 3:** Set inside the Loop. This returns the first two images in the Featured Gallery, as an array, then loops through to display each using an HTML `<img>` tag.

$galleryArray = get_post_gallery_ids( null, 2 );

foreach ( $galleryArray as $id ) {

echo '<img src="' . wp_get_attachment_url( $id ) .'">';

}
You can also customize the returned value from the function to suit your needs. See the full [function documentation](https://github.com/Kelderic/featured-galleries/wiki/get_post_gallery_ids) page for details.

**Example 4:** Set outside the Loop. This uses a specified post ID (431) and returns all images in that post's Featured Gallery, as an array, then loops through to display each using an HTML `<img>` tag.

$galleryArray = get_post_gallery_ids( 431 );

foreach ( $galleryArray as $id ) {

echo '<img src="' . wp_get_attachment_url( $id ) .'">';

}

**Example 5:** Set inside the Loop. This returns all images in the Featured Gallery, as an string, then echos that string to the page. I personally don't see how returning the IDs as a string is useful, but it was requested as a feature a long time ago.

$galleryString = get_post_gallery_ids( null, -1, 'string' );

echo $galleryString; // THIS WOULD ECHO SOMETHING LIKE: 34,6422,4364

= 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 something along these lines:

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' );

That would add Featured Galleries to the custom post type with the slug of 'custom_post_type'. To add it to a custom post type with a slug of 'books', you'd do this:

function add_featured_galleries_to_ctp( $post_types ) {
array_push($post_types, 'books'); // ($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' );
= Custom Post Types =

= Show the Details Sidebar In Media Manager =
The plugin comes with a filter to easily add Featured Galleries to custom post types. See the [`fg_post_types`](https://github.com/Kelderic/featured-galleries/wiki/fg_post_types) documentation page for details.

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:
= Customizing the Media Manager =

function show_fg_sidebar( $show_sidebar ) {
return true; // ($show_sidebar comes in a false)
} add_filter( 'fg_show_sidebar', 'show_fg_sidebar' );
The media manager can be customized in sevearl ways. See the [`fg_show_sidebar`](https://github.com/Kelderic/featured-galleries/wiki/fg_show_sidebar) and [`fg_use_legacy_selection`](https://github.com/Kelderic/featured-galleries/wiki/fg_use_legacy_selection) filter documentation pages for details.

= Want to Help? =

Expand Down

0 comments on commit 9bbc52b

Please sign in to comment.