Opened 11 years ago
Last modified 22 months ago
#12799 new enhancement
Allow gallery shortcode to accept a maximum number of items
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.9 |
Component: | Gallery | Keywords: | dev-feedback has-patch |
Focuses: | Cc: |
Description
A "would be nice" feature of the gallery would be to allow for a maximum number of items to be displayed.
The main use of this feature would be to allow a page to show a "preview" of some of the images contained within one or more subpages, eg:
- Some event
[gallery link="file" columns="4" orderby="rand" maximum="4" id="164"]
- Some other event
[gallery link="file" columns="4" orderby="rand" maximum="4" id="200"]
Attachments (5)
Change History (25)
#2
@
9 years ago
Hi - I have a use case for this - specifically for gallery custom post types where I want to display a subset of the gallery on the archive/ homepage. As such - is there an update for when this might happen as I think it would be really useful.
#3
@
9 years ago
- Keywords has-patch added
12799.diff
adds an optional numberimages=""
parameter to the [gallery] shortcode.
This parameter is named similarly to the numberposts
attribute in get_posts()
.
If the numberimages
parameter is set to a number greater than zero, then it controls the maximum number of images displayed by the [gallery] shortcode.
Examples:
[gallery link="file" columns="4" orderby="rand" numberimages="4" id="256"] [gallery link="file" columns="4" orderby="rand" numberimages="4" include="263,264,261,260,259"]
In both cases, only 4 images (at most) will be displayed.
The code on line 836-839 is only necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="").
#4
follow-up:
↓ 5
@
9 years ago
that looks perfect for my needs - does this diff mean that it will be added to core, or is it just a proposal for inclusion (I'm new to Trac - don't know how it works)?
#5
in reply to:
↑ 4
@
6 years ago
- Keywords dev-feedback needs-refresh added; gallery maximum has-patch removed
- Version changed from 2.9.2 to 2.9
Replying to BinaryMoon:
that looks perfect for my needs - does this diff mean that it will be added to core, or is it just a proposal for inclusion (I'm new to Trac - don't know how it works)?
It means it's something we can merge into core, but not marked for inclusion (that's the milestone for the ticket)
Other devs: Do we want to support a max param, or do we want to relegate that to a plugin to support?
#6
@
6 years ago
- Keywords needs-docs added
I like the idea of having a maximum number of images to display. I could see a use case of this if someone is wanting to randomly cycle through a preset list of images.
I like this...I'll work on updating the patch. I think this will also need docs on the new option.
#7
@
6 years ago
- Keywords has-patch added; needs-refresh needs-docs removed
- Milestone changed from Future Release to 4.4
Woot! Below is the new patch. Tested on the nightly and it seems to be working like a charm now! After using it, I really like the addition. I think it could be useful. It's kinda cool refreshing the page and getting different random images.
I went with maxdisp
as the shortcode attribute for the sake of keeping it short and sweet. Also added docs to the shortcode listing.
Usage looks like the below shortcode:
[gallery include="8,7,6,5,4" maxdisp="2" orderby="rand"]
Would still like a lead dev to thumbs up this so leaving dev feedback.
Patch below!
#8
@
6 years ago
Nice - thanks :)
Not sure about maxdisp as the attribute name though. I'd imagine something like 'count' would be clearer?
To me maxdisp sounds very programmery (like a variable name) and I'm not sure the average user would understand it's use.
#9
@
6 years ago
Thanks.
It is something I needed on several websites. Both max and random. If used in widget and Users dont have access to widget managament better to use "post ID" than "include".
#10
@
6 years ago
Completely agree. It's the robot in me that decided on maxdisp
. I like count
much better. Also, this works just the same with ids=
as well.
[gallery ids="8,7,6,5,4" count="2" orderby="rand"]
Updated patch below!
This ticket was mentioned in Slack in #design by antpb. View the logs.
6 years ago
This ticket was mentioned in Slack in #design by antpb. View the logs.
6 years ago
#13
follow-up:
↓ 14
@
5 years ago
This looks great @dtorbert!
@antpb your most recent diff has a few spacing issues in the first phpdoc block (L1397) and then the array (L1448).
Also, I noticed a typo on L1476:
Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="")`
I believe you meant number of items
.
#14
in reply to:
↑ 13
@
5 years ago
Replying to michaelbeil: Thanks! Good catch. I actually copied the line from a previous diff.
I went ahead and fixed the spacing issue as well. Patch to follow...
This looks great @dtorbert!
@antpb your most recent diff has a few spacing issues in the first phpdoc block (L1397) and then the array (L1448).
Also, I noticed a typo on L1476:
Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="")`
I believe you meant
number of items
.
#16
in reply to:
↑ 12
@
5 years ago
Replying to slackbot:
This ticket was mentioned in Slack in #design by antpb. View the logs.
Having a UI for this by default does not make sense, though an unexposed shortcode attribute seems reasonable. See the discussion for more details.
This ticket was mentioned in Slack in #core by helen. View the logs.
5 years ago
#19
@
5 years ago
I'm not sure count
is the right name for the attribute either, even if that's what it's called in the code.
Suggested replacement for gallery_shortcode()