Gallery Control - Min/Max Images

Is there a way to set a min and a max on the number of images in the new gallery control field?

https://docs.loopsandlogic.com/category/126

Also is this the new control for images instead of the legacy Image control?

After playing with it more, it doesn’t seem like this is supposed to be a replacement for the image control… So is there a missing new control for images?

Also the file option doesn’t work for this since you can’t select from the WP gallery…

Not currently, but it’s in the works.

There’s definitely some functionality missing in the current controls. I’m not sure if the long-term plan is to add an image control or if it’s instead to add to the gallery control to allow it to work with a single image so that the gallery control can be used as a replacement for the legacy image control. Either way, some work to do there.

Yeah, I noticed this too when I tested it out. I asked the dev who’s been working on block controls and they mentioned that this feature existed and was just waiting to be merged into the main plugin. That was a month ago so I just followed up to see what the ETA is on getting that feature merged.

1 Like

I would vote for a separate control for image field vs a gallery. They output different markup, so I think in my mind it would be easier to have a separate control.

1 Like

Just heard back from the dev and I learned a whole lot! Going to have someone put some more work into the docs to make sure we’ve got all this into on there.

Regarding selecting WP media in the gallery control, it turns out that by adding the attribute wp_media="true" to that control, that will allow users to select media from the media library. I’m told this will be set to true by default in the future.

Regarding the ability to set a min/max number of images in a gallery, I got confirmation that this is in the works and also got the tip that there’s a max_upload attribute on the file control that allows setting the maximum allowable files that can be added to the control. There’s no minimum and it might not fit your need if you’re looking for an image-specific control but I figured I’d mention it.

Regarding having a single-image control, I’ve got confirmation that there is a plan to add one eventually. That being said, the only difference will be that the single-image control will have a different interface that lends itself better to adding a single image. From a syntax/markup perspective, the gallery, file, and image controls are/will all use the same Loop/Fields to display data.

And then the last thing, regarding limiting the file type to be uploaded, apparently there’s a mime_types attribute on the file control that allows this. Info on what values that accepts can be found here. So for example, if you wanted to limit your file upload to just images, you could write:

<Control type="file" name="test" wp_media="true" mime_types="image" />

This value also accepts lists so if you wanted to get more granular with specific file types you could add something like this:

<Control type="file" name="test" wp_media="true">
  <List mime_types>
    <Item>image/jpeg</Item>
    <Item>image/png</Item>
  </List>
</Control> 

I’ll ask that this be properly documented. I’m not sure if this is its final form since in my view it seems a little unwieldy but it also makes sense since it’s using data that’s core to WordPress. I’ll make sure this gets added to the docs but for now you’ve at least go these examples to go off.

Also, I’m told that there are some issues with both those controls (file and gallery) in the current version of Tangible Blocks and that they should be more stable in the next release.

Hope that’s all useful information!

1 Like

Great info! Thanks!

What about user selected image size?
Screen Shot 2023-04-17 at 16.26.00

(and then I guess forced image size can happen in the template of the block?)

Yeah, I think the individual image control makes sense too since the verbiage surrounding it will vary as well (ie: Create Gallery, Edit Gallery, Add images to gallery, etc)
f1CFwnn5LqxYxX62waGdnzKIH